Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions prod-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,16 @@ fi
if [[ -n "$PID" ]]; then
say "Safe restart of running bot (PID: $PID)"
fi
command -v systemctl >/dev/null 2>&1 && [[ -f "$SERVICE_FILE" ]] && systemctl restart "${APP_NAME}.service" 2>/dev/null || {
if command -v systemctl >/dev/null 2>&1 && [[ -f "$SERVICE_FILE" ]]; then
systemctl restart "${APP_NAME}.service" 2>/dev/null || true
else
[[ -n "$PID" ]] && kill "$PID" 2>/dev/null || true
nohup node "$PROJECT_DIR/index.js" >> "$MAIN_LOG" 2>> "$ERROR_LOG" < /dev/null &
disown

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Because the script runs with set -e in a non-interactive shell, the bare disown call in the manual restart path will typically fail with "no job control" and exit status 1, causing the entire deployment script to abort on non-systemd systems immediately after starting the bot and before health checks and reporting run; this should be guarded (as in other parts of the script) so that a non-zero status from disown does not terminate the script. [logic error]

Severity Level: Major ⚠️
- ❌ prod-run.sh aborts on non-systemd hosts after restart.
- ⚠️ Post-start health checks never execute on affected systems.
- ⚠️ Telegram deploy health summary is never sent there.
Suggested change
disown
disown || true
Steps of Reproduction ✅
1. On a host without systemd (no `systemctl` in PATH), run `npm run prod` from
`/workspace/Runewager` which executes `./prod-run.sh` (entrypoint defined in
`package.json:10-15`).

2. Observe `prod-run.sh` starts with `set -euo pipefail` at `prod-run.sh:9`, meaning any
simple command returning non-zero (and not guarded with `|| true`) aborts the script.

3. During section "10) Safe restart" at `prod-run.sh:38-48`, because `command -v
systemctl` fails and `SERVICE_FILE` is irrelevant, the script takes the `else` branch at
`prod-run.sh:42-48`, runs `nohup node "$PROJECT_DIR/index.js" ... &` followed by the bare
`disown` at `prod-run.sh:47` (diff line 506).

4. In this non-interactive, no-job-control shell, `disown` exits with status 1 ("no job
control"); due to `set -e` this non-zero exit causes the entire `prod-run.sh` process to
terminate immediately, so the subsequent post-start health check and Telegram reporting
block at `prod-run.sh:49-79` never execute.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** prod-run.sh
**Line:** 506:506
**Comment:**
	*Logic Error: Because the script runs with `set -e` in a non-interactive shell, the bare `disown` call in the manual restart path will typically fail with "no job control" and exit status 1, causing the entire deployment script to abort on non-systemd systems immediately after starting the bot and before health checks and reporting run; this should be guarded (as in other parts of the script) so that a non-zero status from `disown` does not terminate the script.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

sleep 3
PID="$(get_bot_pid)"
}
fi
# Always refresh PID after restart so step 11 knows the live process
sleep 3
PID="$(get_bot_pid)"

# =========================================================
# 11) POST-START HEALTH CHECK + TELEGRAM REPORT (single pass)
Expand Down