|
#!/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}" |
|
|
|
|
|
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" |
|
} |
|
|
|
|
|
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 |
|
} |
|
|
|
|
|
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 |
|
|
|
|
|
export N8N_ENCRYPTION_KEY="${N8N_ENCRYPTION_KEY:-n8n8n8n}" |
|
|
|
export NODE_FUNCTION_ALLOW_BUILTIN=* |
|
|
|
export NODE_FUNCTION_ALLOW_EXTERNAL=* |
|
|
|
export EXECUTIONS_DATA_PRUNE=true |
|
|
|
export EXECUTIONS_DATA_MAX_AGE=36 |
|
|
|
export EXECUTIONS_DATA_PRUNE_MAX_COUNT=1000 |
|
|
|
export EXECUTIONS_DATA_SAVE_ON_ERROR=all |
|
|
|
export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all |
|
|
|
export EXECUTIONS_DATA_SAVE_ON_PROGRESS=false |
|
|
|
export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false |
|
|
|
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 |
|
|