-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
31 lines (26 loc) · 990 Bytes
/
Copy pathstart.sh
File metadata and controls
31 lines (26 loc) · 990 Bytes
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
#!/usr/bin/env bash
set -euo pipefail
# Defaults — Railway sets PORT; WORKER_PORT is internal only.
: "${PORT:=3000}"
: "${WORKER_PORT:=8080}"
: "${HOSTNAME:=0.0.0.0}"
echo "[start] launching worker on :${WORKER_PORT}"
( cd /app && WORKER_PORT="${WORKER_PORT}" npx --no-install tsx worker/index.ts ) &
WORKER_PID=$!
echo "[start] launching next.js on :${PORT}"
( cd /app && PORT="${PORT}" HOSTNAME="${HOSTNAME}" node server.js ) &
APP_PID=$!
term() {
echo "[start] received signal, shutting down"
kill -TERM "${APP_PID}" "${WORKER_PID}" 2>/dev/null || true
wait "${APP_PID}" "${WORKER_PID}" 2>/dev/null || true
exit 0
}
trap term SIGTERM SIGINT
# Exit as soon as either child dies, then kill the other so Railway restarts.
wait -n "${APP_PID}" "${WORKER_PID}"
EXIT_CODE=$?
echo "[start] one process exited (code=${EXIT_CODE}), tearing down"
kill -TERM "${APP_PID}" "${WORKER_PID}" 2>/dev/null || true
wait "${APP_PID}" "${WORKER_PID}" 2>/dev/null || true
exit "${EXIT_CODE}"