File size: 2,837 Bytes
e4fbb50
d57197c
e4fbb50
59802b0
 
 
e4fbb50
 
 
ad5bc33
 
 
 
 
 
 
 
 
d57197c
 
 
ad5bc33
d57197c
 
 
 
 
0069402
 
 
 
 
 
 
 
 
 
 
 
 
ca1b28f
 
 
 
 
 
 
 
 
d57197c
0069402
ca1b28f
d57197c
e4fbb50
d57197c
e4fbb50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0069402
 
 
 
e4fbb50
d57197c
 
 
ad5bc33
 
 
 
 
0069402
 
 
ad5bc33
ca1b28f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e

# 导入环境变量
source /home/pn/.env

current_time=$(date +"%Y-%m-%d %H:%M:%S")
echo "Starting n8n at $current_time"

# 输出数据库配置信息
echo "Database Configuration:"
echo "Host: ${DB_POSTGRESDB_HOST}"
echo "Port: ${DB_POSTGRESDB_PORT}"
echo "User: ${DB_POSTGRESDB_USER}"
echo "Database: ${DB_POSTGRESDB_DATABASE}"
echo "Type: ${DB_TYPE}"

# 等待 PostgreSQL 就绪, 并输出连接信息,超时10秒
wait_for_postgres() {
    echo "Waiting for PostgreSQL to start..."
    while ! nc -z ${DB_POSTGRESDB_HOST} ${DB_POSTGRESDB_PORT}; do
        echo "Trying to connect to PostgreSQL at ${DB_POSTGRESDB_HOST}:${DB_POSTGRESDB_PORT}..."
        sleep 1
    done
    echo "PostgreSQL started"
}

# 启动 Redis 服务
start_redis() {
    echo "Starting Redis server..."
    redis-server --daemonize yes
    sleep 1
    if redis-cli ping > /dev/null 2>&1; then
        echo "Redis server started successfully"
    else
        echo "Failed to start Redis server"
        exit 1
    fi
}

# 在 start_redis() 函数后添加检查函数
check_redis_queue() {
    echo "检查 Redis 队列状态..."
    redis-cli info | grep connected_clients
    redis-cli keys "${N8N_QUEUE_BULL_REDIS_PREFIX}*"
    echo "Redis 队列键值列表:"
    redis-cli keys "*" | grep "bull"
}

wait_for_postgres
start_redis
check_redis_queue

# 设置 N8N 环境变量
export N8N_ENCRYPTION_KEY="${N8N_ENCRYPTION_KEY:-n8n8n8n}"
# 允许使用所有内建模块
export NODE_FUNCTION_ALLOW_BUILTIN=*
# 允许使用外部 npm 模块
export NODE_FUNCTION_ALLOW_EXTERNAL=*
# Activate automatic data pruning
export EXECUTIONS_DATA_PRUNE=true
# Number of hours after execution that n8n deletes data
export EXECUTIONS_DATA_MAX_AGE=36
# Number of executions to store
export EXECUTIONS_DATA_PRUNE_MAX_COUNT=1000
# Save executions ending in errors
export EXECUTIONS_DATA_SAVE_ON_ERROR=all
# Save successful executions
export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all
# Don't save node progress for each execution
export EXECUTIONS_DATA_SAVE_ON_PROGRESS=false
# Don't save manually launched executions
export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
# 将以下环境变量设置为 false,以阻止 n8n 连接到其服务器
export N8N_DIAGNOSTICS_ENABLED=false
export N8N_VERSION_NOTIFICATIONS_ENABLED=true
export N8N_TEMPLATES_ENABLED=false

# 设置文件权限
export N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true

echo "Starting n8n with the following configuration:"
echo "N8N_HOST: ${N8N_HOST}"
echo "N8N_PORT: ${N8N_PORT}"
echo "N8N_PROTOCOL: ${N8N_PROTOCOL}"
echo "WEBHOOK_URL: ${WEBHOOK_URL}"
echo "QUEUE_BULL_REDIS_HOST: ${QUEUE_BULL_REDIS_HOST}"
echo "QUEUE_BULL_REDIS_PORT: ${QUEUE_BULL_REDIS_PORT}"
echo "EXECUTIONS_MODE: ${EXECUTIONS_MODE}"

# 将输出重定向到日志文件
exec n8n start 2>&1 | tee /home/pn/.n8n/n8n.log