-
Notifications
You must be signed in to change notification settings - Fork 0
Claude/cpu guard script dn d8u #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a3f9145
b9be6f9
ca6af01
3faf7e8
90742a6
4038b9a
fd57310
dd13398
5e08dee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -385,13 +385,44 @@ if [[ -f "$DISK_PROTECT_SCRIPT" ]] && command -v crontab >/dev/null 2>&1; then | |||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # --------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| # 9c) Kill anything blocking the bot port before restart | ||||||||||||||||||||||||||||||||
| # 9c) Aggressively clear port conflicts BEFORE restart | ||||||||||||||||||||||||||||||||
| # Kills any process (including stray backend.js, old node instances) | ||||||||||||||||||||||||||||||||
| # holding the bot port so systemd never races against a squatter. | ||||||||||||||||||||||||||||||||
| PORT_PRESTART="$(read_env_value PORT || echo 3000)" | ||||||||||||||||||||||||||||||||
| PORT_PRESTART="${PORT_PRESTART:-3000}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| _kill_port_squatters() { | ||||||||||||||||||||||||||||||||
| local port="$1" own_pid="${2:-}" | ||||||||||||||||||||||||||||||||
| local pids pid | ||||||||||||||||||||||||||||||||
| # Use lsof if available (most reliable), fall back to port_listener_pids | ||||||||||||||||||||||||||||||||
| if command -v lsof >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||
| pids="$(lsof -t -iTCP:"${port}" -sTCP:LISTEN 2>/dev/null | sort -u || true)" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| pids="$(port_listener_pids "$port")" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| for pid in $pids; do | ||||||||||||||||||||||||||||||||
| [[ -z "$pid" ]] && continue | ||||||||||||||||||||||||||||||||
| [[ -n "$own_pid" && "$pid" == "$own_pid" ]] && continue | ||||||||||||||||||||||||||||||||
| warn "Pre-start: killing PID $pid squatting port ${port}" | ||||||||||||||||||||||||||||||||
| kill -TERM "$pid" 2>/dev/null || true | ||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||
| kill -0 "$pid" 2>/dev/null && { kill -KILL "$pid" 2>/dev/null || true; } | ||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if is_port_listening "$PORT_PRESTART"; then | ||||||||||||||||||||||||||||||||
| say "Port $PORT_PRESTART in use — freeing before restart..." | ||||||||||||||||||||||||||||||||
| free_port_if_conflicted "$PORT_PRESTART" "${PID:-}" || true | ||||||||||||||||||||||||||||||||
| say "Port $PORT_PRESTART in use — aggressively clearing before restart..." | ||||||||||||||||||||||||||||||||
| _kill_port_squatters "$PORT_PRESTART" "${PID:-}" | ||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||
| # Second pass — if still occupied, SIGKILL everything left | ||||||||||||||||||||||||||||||||
| if is_port_listening "$PORT_PRESTART"; then | ||||||||||||||||||||||||||||||||
| warn "Port $PORT_PRESTART still occupied — forcing SIGKILL..." | ||||||||||||||||||||||||||||||||
| if command -v lsof >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||
| lsof -t -iTCP:"${PORT_PRESTART}" -sTCP:LISTEN 2>/dev/null \ | ||||||||||||||||||||||||||||||||
| | xargs -r kill -9 2>/dev/null || true | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # --------------------------------------------------------- | ||||||||||||||||||||||||||||||||
|
|
@@ -476,168 +507,54 @@ command -v systemctl >/dev/null 2>&1 && [[ -f "$SERVICE_FILE" ]] && systemctl re | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # ========================================================= | ||||||||||||||||||||||||||||||||
| # 11) GOD-MODE HEAL LOGIC + TELEGRAM REPORT | ||||||||||||||||||||||||||||||||
| # 11) POST-START HEALTH CHECK + TELEGRAM REPORT (single pass) | ||||||||||||||||||||||||||||||||
| # ========================================================= | ||||||||||||||||||||||||||||||||
| say "⚡ Running integrated God-Mode Heal..." | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Load admin IDs and bot token | ||||||||||||||||||||||||||||||||
| ADMIN_IDS=$(grep -E '^ADMIN_IDS=' .env | cut -d= -f2 | tr -d '"') | ||||||||||||||||||||||||||||||||
| TELEGRAM_BOT_TOKEN=$(grep -E '^TELEGRAM_BOT_TOKEN=' .env | cut -d= -f2 | tr -d '"') | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| PORT=$(grep -E '^PORT=' .env | cut -d= -f2 || true) | ||||||||||||||||||||||||||||||||
| PORT=${PORT:-3000} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| BLOCKING_PID=$(lsof -ti :"$PORT" || true) | ||||||||||||||||||||||||||||||||
| if [[ -n "$BLOCKING_PID" ]]; then | ||||||||||||||||||||||||||||||||
| say "🚨 Port $PORT blocked by PID $BLOCKING_PID — killing..." | ||||||||||||||||||||||||||||||||
| kill -9 "$BLOCKING_PID" || true | ||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||
| say "♻️ Restarting ${APP_NAME} after freeing port..." | ||||||||||||||||||||||||||||||||
| systemctl restart "${APP_NAME}" 2>/dev/null || nohup node "$PROJECT_DIR/index.js" >> "$MAIN_LOG" 2>> "$ERROR_LOG" < /dev/null & | ||||||||||||||||||||||||||||||||
| sleep 2 | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| say "✅ Port $PORT free — continuing" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| HEALTH_OK=false | ||||||||||||||||||||||||||||||||
| if curl -sf "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||
| HEALTH_OK=true | ||||||||||||||||||||||||||||||||
| say "💓 Health endpoint OK" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| say "❌ Health endpoint FAILED — capturing logs" | ||||||||||||||||||||||||||||||||
| echo "---- Last 50 lines of $MAIN_LOG ----"; tail -n 50 "$MAIN_LOG" | ||||||||||||||||||||||||||||||||
| echo "---- Last 50 lines of $ERROR_LOG ----"; tail -n 50 "$ERROR_LOG" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Telegram admin notification | ||||||||||||||||||||||||||||||||
| if [[ -n "$TELEGRAM_BOT_TOKEN" && -n "$ADMIN_IDS" ]]; then | ||||||||||||||||||||||||||||||||
| for ADMIN_ID in ${ADMIN_IDS//,/ }; do | ||||||||||||||||||||||||||||||||
| REPORT=$( (tail -n 50 "$MAIN_LOG"; tail -n 50 "$ERROR_LOG") | sed 's/"/\\"/g') | ||||||||||||||||||||||||||||||||
| curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ | ||||||||||||||||||||||||||||||||
| -d chat_id="$ADMIN_ID" \ | ||||||||||||||||||||||||||||||||
| -d parse_mode="Markdown" \ | ||||||||||||||||||||||||||||||||
| -d text="🏁 *Runewager Heal Report*\nHealth: $( [[ "$HEALTH_OK" == true ]] && echo '✅ OK' || echo '❌ FAILED')\nPort: $PORT\nPID: ${PID:-none}\n\n_Last 50 log lines:_\n\`\`\`${REPORT}\`\`\`" >/dev/null 2>&1 || true | ||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| SYSTEMD_ACTIVE="$(systemctl is-active "${APP_NAME}.service" 2>/dev/null || echo inactive)" | ||||||||||||||||||||||||||||||||
| HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_PORT%%/*}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 20 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if is_port_listening "$HEALTH_PORT"; then | ||||||||||||||||||||||||||||||||
| PORT_STATUS="listening" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| SYSTEMD_ACTIVE="$(systemctl is-active "${APP_NAME}.service" 2>/dev/null || echo inactive)" | ||||||||||||||||||||||||||||||||
| HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_PORT%%/*}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 20 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| say "Running post-start health check..." | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| PRECHECK_HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| PRECHECK_PORT="${PRECHECK_HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| PRECHECK_PORT="${PRECHECK_PORT%%/*}" | ||||||||||||||||||||||||||||||||
| if is_port_listening "$PRECHECK_PORT"; then | ||||||||||||||||||||||||||||||||
| free_port_if_conflicted "$PRECHECK_PORT" "$PID" || true | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if command -v systemctl >/dev/null 2>&1 && [[ -f "$SERVICE_FILE" ]]; then | ||||||||||||||||||||||||||||||||
| if systemctl restart "${APP_NAME}.service" 2>&1; then | ||||||||||||||||||||||||||||||||
| sleep 3 | ||||||||||||||||||||||||||||||||
| PID="$(get_bot_pid)" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| warn "systemctl restart failed — falling back to kill+nohup" | ||||||||||||||||||||||||||||||||
| [[ -n "$PID" ]] && { kill "$PID" 2>/dev/null || true; sleep 2; } | ||||||||||||||||||||||||||||||||
| nohup node "$PROJECT_DIR/index.js" \ | ||||||||||||||||||||||||||||||||
| >> "$MAIN_LOG" 2>> "$ERROR_LOG" < /dev/null & | ||||||||||||||||||||||||||||||||
| disown || true | ||||||||||||||||||||||||||||||||
| sleep 3 | ||||||||||||||||||||||||||||||||
| PID="$(get_bot_pid)" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| SYSTEMD_ACTIVE="$(systemctl is-active "${APP_NAME}.service" 2>/dev/null || echo inactive)" | ||||||||||||||||||||||||||||||||
| HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_PORT%%/*}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 20 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if is_port_listening "$HEALTH_PORT"; then | ||||||||||||||||||||||||||||||||
| PORT_STATUS="listening" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| SYSTEMD_ACTIVE="$(systemctl is-active "${APP_NAME}.service" 2>/dev/null || echo inactive)" | ||||||||||||||||||||||||||||||||
| HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_PORT%%/*}" | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 20 2; then | ||||||||||||||||||||||||||||||||
| # Wait up to 30s for health (15 x 2s) — single pass | ||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 15 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Auto-recover from port conflicts, then retry health once. | ||||||||||||||||||||||||||||||||
| # One auto-recovery: clear any squatter and restart once | ||||||||||||||||||||||||||||||||
| if is_port_listening "$HEALTH_PORT"; then | ||||||||||||||||||||||||||||||||
| free_port_if_conflicted "$HEALTH_PORT" "$PID" || true | ||||||||||||||||||||||||||||||||
| warn "Port $HEALTH_PORT still squatted after start — forcing clear + one restart" | ||||||||||||||||||||||||||||||||
| _kill_port_squatters "$HEALTH_PORT" "${PID:-}" | ||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||
| 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; sleep 2; } | ||||||||||||||||||||||||||||||||
| [[ -n "${PID:-}" ]] && { kill "$PID" 2>/dev/null || true; sleep 2; } | ||||||||||||||||||||||||||||||||
| nohup node "$PROJECT_DIR/index.js" >> "$MAIN_LOG" 2>> "$ERROR_LOG" < /dev/null & | ||||||||||||||||||||||||||||||||
| disown || true | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| sleep 3 | ||||||||||||||||||||||||||||||||
| PID="$(get_bot_pid)" | ||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 10 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| # Final health probe (10 x 2s) | ||||||||||||||||||||||||||||||||
| wait_for_health "$HEALTH_URL" 10 2 && HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if is_port_listening "$HEALTH_PORT"; then | ||||||||||||||||||||||||||||||||
| PORT_STATUS="listening" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| SYSTEMD_ACTIVE="$(systemctl is-active "${APP_NAME}.service" 2>/dev/null || echo inactive)" | ||||||||||||||||||||||||||||||||
| HEALTH_URL="$(resolve_health_url)" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_URL#*://127.0.0.1:}" | ||||||||||||||||||||||||||||||||
| HEALTH_PORT="${HEALTH_PORT%%/*}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if wait_for_health "$HEALTH_URL" 20 2; then | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="healthy" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| HEALTH_STATUS="unhealthy" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| is_port_listening "$HEALTH_PORT" && PORT_STATUS="listening" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if is_port_listening "$HEALTH_PORT"; then | ||||||||||||||||||||||||||||||||
| PORT_STATUS="listening" | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| PORT_STATUS="not-listening" | ||||||||||||||||||||||||||||||||
| # Telegram admin notification | ||||||||||||||||||||||||||||||||
| _ADMIN_IDS="$(read_env_value ADMIN_IDS || true)" | ||||||||||||||||||||||||||||||||
| _BOT_TOKEN="$(read_env_value TELEGRAM_BOT_TOKEN || true)" | ||||||||||||||||||||||||||||||||
| if [[ -n "$_BOT_TOKEN" && -n "$_ADMIN_IDS" ]]; then | ||||||||||||||||||||||||||||||||
| _REPORT="$(( tail -n 30 "$MAIN_LOG"; tail -n 20 "$ERROR_LOG" ) 2>/dev/null \ | ||||||||||||||||||||||||||||||||
| | sed 's/"/\\"/g' | head -c 3500)" | ||||||||||||||||||||||||||||||||
|
Comment on lines
+550
to
+551
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: _REPORT is computed but never used in the Telegram notification.
|
||||||||||||||||||||||||||||||||
| for _AID in ${_ADMIN_IDS//,/ }; do | ||||||||||||||||||||||||||||||||
| curl -s -X POST "https://api.telegram.org/bot${_BOT_TOKEN}/sendMessage" \ | ||||||||||||||||||||||||||||||||
| -d chat_id="$_AID" \ | ||||||||||||||||||||||||||||||||
| -d parse_mode="Markdown" \ | ||||||||||||||||||||||||||||||||
| -d text="Deploy complete: Health $( [[ "$HEALTH_STATUS" == healthy ]] && echo OK || echo FAILED) Port: $HEALTH_PORT PID: ${PID:-none}" >/dev/null 2>&1 || true | ||||||||||||||||||||||||||||||||
|
Comment on lines
+550
to
+556
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The Telegram deploy notification block attempts to build a log snippet using arithmetic expansion ( Severity Level: Critical 🚨- ❌ prod-run.sh exits when Telegram alerts are configured.
- ⚠️ Telegram deploy messages lack intended log context.
Suggested change
Steps of Reproduction ✅1. Ensure Telegram notifications are configured by setting `TELEGRAM_BOT_TOKEN` and
`ADMIN_IDS` in `.env`, which are read by `read_env_value` at `prod-run.sh:547-548`.
2. Deploy using the documented entrypoint, e.g. run `npm run prod` (which invokes
`./prod-run.sh` per `package.json:14`) or execute `bash prod-run.sh` from the project
root.
3. After the bot is restarted and the health check passes/finalizes (logic at
`prod-run.sh:514-542`), execution reaches the Telegram admin notification block at
`prod-run.sh:546-557`.
4. With `set -euo pipefail` enabled at `prod-run.sh:9`, the line `_REPORT="$(( tail -n 30
"$MAIN_LOG"; tail -n 20 "$ERROR_LOG" ) 2>/dev/null \` at `prod-run.sh:550-551` is parsed
as arithmetic expansion: `tail`/`sed` tokens are not valid arithmetic, causing a Bash
"syntax error in expression" and immediate script exit before any `tail` commands run or
any `curl` notification is sent; even if `set -e` were relaxed, `_REPORT` would not
contain the intended log snippet and is never interpolated into the `text` field at
`prod-run.sh:556`, so admins would receive at most a bare status line without logs.Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** prod-run.sh
**Line:** 550:556
**Comment:**
*Logic Error: The Telegram deploy notification block attempts to build a log snippet using arithmetic expansion (`$(( ... ))`) instead of command substitution (`$( ... )`), so the `tail` commands are never executed as commands, and the resulting `_REPORT` content is meaningless and never included in the message body; switch to proper command substitution and append `_REPORT` to the `text` payload so admins actually receive the intended log excerpt.
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. |
||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| say "✔ Systemd service: ${SYSTEMD_ACTIVE}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): SYSTEMD_ACTIVE can become stale after the auto-recovery restart branch.
Because SYSTEMD_ACTIVE is set only once and reused in the final summary, the reported status may not match the actual state after
systemctl restartruns in the auto-recovery path. Please either move thesystemctl is-activecall to just before the final summary, or recompute SYSTEMD_ACTIVE after the restart so the final line reflects the post-heal state.