Spaces:
Sleeping
Sleeping
Delete start.sh
Browse files
start.sh
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env bash
|
| 2 |
-
###############################################################################
|
| 3 |
-
# start.sh
|
| 4 |
-
#
|
| 5 |
-
# Launches nginx (public-facing, security headers + rate limiting) and n8n
|
| 6 |
-
# (internal, 127.0.0.1 only) as sibling processes inside the same container.
|
| 7 |
-
# Traps SIGTERM/SIGINT to shut both down gracefully, which matters on
|
| 8 |
-
# Hugging Face Spaces where containers are stopped/restarted routinely
|
| 9 |
-
# during redeploys and sleep/wake cycles.
|
| 10 |
-
###############################################################################
|
| 11 |
-
set -uo pipefail
|
| 12 |
-
|
| 13 |
-
N8N_PID=""
|
| 14 |
-
NGINX_PID=""
|
| 15 |
-
|
| 16 |
-
log() {
|
| 17 |
-
echo "[start.sh] $(date -u +'%Y-%m-%dT%H:%M:%SZ') $*"
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
shutdown() {
|
| 21 |
-
log "Received shutdown signal. Stopping services gracefully..."
|
| 22 |
-
|
| 23 |
-
if [ -n "$NGINX_PID" ] && kill -0 "$NGINX_PID" 2>/dev/null; then
|
| 24 |
-
log "Stopping nginx (pid $NGINX_PID)..."
|
| 25 |
-
nginx -c /tmp/nginx.conf -s quit 2>/dev/null || kill -TERM "$NGINX_PID" 2>/dev/null
|
| 26 |
-
fi
|
| 27 |
-
|
| 28 |
-
if [ -n "$N8N_PID" ] && kill -0 "$N8N_PID" 2>/dev/null; then
|
| 29 |
-
log "Stopping n8n (pid $N8N_PID)..."
|
| 30 |
-
kill -TERM "$N8N_PID" 2>/dev/null
|
| 31 |
-
# Give n8n time to finish in-flight executions before force-killing.
|
| 32 |
-
for i in $(seq 1 30); do
|
| 33 |
-
kill -0 "$N8N_PID" 2>/dev/null || break
|
| 34 |
-
sleep 1
|
| 35 |
-
done
|
| 36 |
-
kill -0 "$N8N_PID" 2>/dev/null && kill -KILL "$N8N_PID" 2>/dev/null
|
| 37 |
-
fi
|
| 38 |
-
|
| 39 |
-
log "Shutdown complete."
|
| 40 |
-
exit 0
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
trap shutdown SIGTERM SIGINT
|
| 44 |
-
|
| 45 |
-
log "Starting n8n on 127.0.0.1:${N8N_PORT} ..."
|
| 46 |
-
n8n start &
|
| 47 |
-
N8N_PID=$!
|
| 48 |
-
|
| 49 |
-
log "Starting nginx on 0.0.0.0:${PORT} ..."
|
| 50 |
-
nginx -c /tmp/nginx.conf -g "daemon off;" &
|
| 51 |
-
NGINX_PID=$!
|
| 52 |
-
|
| 53 |
-
log "n8n pid=$N8N_PID, nginx pid=$NGINX_PID"
|
| 54 |
-
|
| 55 |
-
# If either process dies unexpectedly, bring the whole container down so
|
| 56 |
-
# the orchestrator (HF Spaces / docker) restarts it cleanly.
|
| 57 |
-
while true; do
|
| 58 |
-
if ! kill -0 "$N8N_PID" 2>/dev/null; then
|
| 59 |
-
log "n8n process exited unexpectedly. Shutting down."
|
| 60 |
-
shutdown
|
| 61 |
-
fi
|
| 62 |
-
if ! kill -0 "$NGINX_PID" 2>/dev/null; then
|
| 63 |
-
log "nginx process exited unexpectedly. Shutting down."
|
| 64 |
-
shutdown
|
| 65 |
-
fi
|
| 66 |
-
sleep 3
|
| 67 |
-
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|