somratpro commited on
Commit
b46eebe
Β·
1 Parent(s): dd47a40

Fix: Move Cloudflare keepalive setup before health-server to avoid race condition

Browse files

The health-server was starting before the keepalive setup script finished
writing the status file. This caused a race condition where users would see
"Worker pending or failed" until the setup completed. Now the setup runs
before health-server starts, ensuring the status file exists before any
requests are served.

Files changed (1) hide show
  1. start.sh +6 -5
start.sh CHANGED
@@ -244,6 +244,12 @@ if [ -n "${CLOUDFLARE_PROXY_URL:-}" ] && [ -f /opt/cloudflare-proxy.js ]; then
244
  export NODE_OPTIONS="${NODE_OPTIONS:-} --require /opt/cloudflare-proxy.js"
245
  fi
246
 
 
 
 
 
 
 
247
  # ── Background HF sync loop ──────────────────────────────────────────────────
248
  SYNC_PID=""
249
  if [ -n "${HF_TOKEN:-}" ]; then
@@ -261,11 +267,6 @@ fi
261
  node /opt/healthsrv/health-server.js &
262
  HEALTH_PID=$!
263
 
264
- if [ -n "${CLOUDFLARE_WORKERS_TOKEN:-}" ]; then
265
- echo "Setting up Cloudflare KeepAlive monitor..."
266
- python3 /opt/cloudflare-keepalive-setup.py || true
267
- fi
268
-
269
  sleep 1
270
 
271
  # ── Postiz: nginx + PM2 (mirrors upstream CMD `nginx && pnpm run pm2`) ───────
 
244
  export NODE_OPTIONS="${NODE_OPTIONS:-} --require /opt/cloudflare-proxy.js"
245
  fi
246
 
247
+ # ── Cloudflare KeepAlive worker ──────────────────────────────────────────────
248
+ if [ -n "${CLOUDFLARE_WORKERS_TOKEN:-}" ]; then
249
+ echo "Setting up Cloudflare KeepAlive worker..."
250
+ python3 /opt/cloudflare-keepalive-setup.py || true
251
+ fi
252
+
253
  # ── Background HF sync loop ──────────────────────────────────────────────────
254
  SYNC_PID=""
255
  if [ -n "${HF_TOKEN:-}" ]; then
 
267
  node /opt/healthsrv/health-server.js &
268
  HEALTH_PID=$!
269
 
 
 
 
 
 
270
  sleep 1
271
 
272
  # ── Postiz: nginx + PM2 (mirrors upstream CMD `nginx && pnpm run pm2`) ───────