Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 17 additions & 2 deletions scripts/runewager_redeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ _stop_bot_service() {
else
warn "${BOT_SERVICE} service was not running (OK)"
fi

# Stop legacy service names so they can't restart and steal port ${BOT_PORT}
# while this redeploy is in progress. Failures are non-fatal.
local _legacy
for _legacy in "runewager-bot" "runewager_bot"; do
if [[ "$_legacy" != "$BOT_SERVICE" ]] \
&& systemctl is-active --quiet "$_legacy" 2>/dev/null; then
warn "Legacy service '${_legacy}' is running — stopping to prevent port conflict"
systemctl stop "$_legacy" 2>/dev/null || true
fi
done
Comment on lines +125 to +134

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: The legacy service stopping block ignores the dry-run flag and calls systemctl stop directly, so running the script with --dry-run will still stop any legacy systemd units, violating the documented "no action" contract for dry runs and potentially causing unexpected service interruption. [logic error]

Severity Level: Major ⚠️
- ⚠️ Dry-run redeploy unexpectedly stops legacy bot services.
- ⚠️ Violates documented "print steps, no action" contract.
- ⚠️ Operators may cause downtime while testing changes.
Suggested change
# Stop legacy service names so they can't restart and steal port ${BOT_PORT}
# while this redeploy is in progress. Failures are non-fatal.
local _legacy
for _legacy in "runewager-bot" "runewager_bot"; do
if [[ "$_legacy" != "$BOT_SERVICE" ]] \
&& systemctl is-active --quiet "$_legacy" 2>/dev/null; then
warn "Legacy service '${_legacy}' is running — stopping to prevent port conflict"
systemctl stop "$_legacy" 2>/dev/null || true
fi
done
# Stop legacy service names so they can't restart and steal port ${BOT_PORT}
# while this redeploy is in progress. Failures are non-fatal.
local _legacy
for _legacy in "runewager-bot" "runewager_bot"; do
if [[ "$_legacy" != "$BOT_SERVICE" ]] \
&& systemctl is-active --quiet "$_legacy" 2>/dev/null; then
warn "Legacy service '${_legacy}' is running — stopping to prevent port conflict"
if (( DRY_RUN )); then
warn "[DRY-RUN] would stop legacy service '${_legacy}'"
else
systemctl stop "$_legacy" 2>/dev/null || true
fi
fi
done
Steps of Reproduction ✅
1. On a host where this repo is deployed, ensure a legacy systemd unit is present and
active, e.g. run `systemctl start runewager-bot` so that `systemctl is-active
runewager-bot` returns "active".

2. Execute the redeploy script in dry-run mode: `sudo ./scripts/runewager_redeploy.sh
--dry-run` (entrypoint `main()` in `scripts/runewager_redeploy.sh` near the end of the
file parses `--dry-run` and sets `DRY_RUN=1` before calling `_stop_bot_service`).

3. During STEP 1, function `_stop_bot_service()` at
`scripts/runewager_redeploy.sh:117-135` runs; after handling `$BOT_SERVICE`, it enters the
legacy loop at lines 125-134, where it checks `systemctl is-active --quiet "$_legacy"`
and, if active, prints the warning and executes `systemctl stop "$_legacy" 2>/dev/null ||
true` without consulting `DRY_RUN`.

4. After the script finishes, verify that the legacy service has been stopped by running
`systemctl is-active runewager-bot` and observing it is no longer "active", despite the
script being invoked with `--dry-run` and the header comment advertising `--dry-run #
print steps, no action`.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** scripts/runewager_redeploy.sh
**Line:** 125:134
**Comment:**
	*Logic Error: The legacy service stopping block ignores the dry-run flag and calls `systemctl stop` directly, so running the script with `--dry-run` will still stop any legacy systemd units, violating the documented "no action" contract for dry runs and potentially causing unexpected service interruption.

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.
👍 | 👎

}

# ─────────────────────────────── STEP 2: KILL PORT ───────────────────────────
Expand Down Expand Up @@ -260,7 +271,7 @@ _health_check() {
echo "$_payload" | jq . 2>/dev/null | head -20 | sed 's/^/ /' \
|| echo "$_payload" | head -20 | sed 's/^/ /'
else
echo "$_payload" | head -20 | sed 's/^/ /'
printf '%s\n' "$_payload" | head -20 | sed 's/^/ /'
fi
return 0
fi
Expand Down Expand Up @@ -320,7 +331,11 @@ _summary() {

for svc in "$BOT_SERVICE" "rw_cpu_guard"; do
local state
state=$(systemctl is-active "$svc" 2>/dev/null) || state="not-found"
# systemctl is-active exits non-zero for failed/inactive/unknown too,
# so capture the printed state string; only default to "not-found" when
# the command produces no output at all (unit truly unknown to systemd).
state=$(systemctl is-active "$svc" 2>/dev/null)
[[ -z "$state" ]] && state="not-found"
if [[ "$state" == "active" ]]; then
ok " ${svc}: ${state}"
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/rw_cpu_guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ _run_forensics() {
fi

# ── 1-second CPU tracer (catches sub-8s spikes the guard daemon may miss) ─
echo "timestamp,pid,ppid,cpu%,mem%,cmd" > "$trace"
echo "timestamp,pid,ppid,cpu%,mem%,args" > "$trace"
( while true; do
# Use 'args' (not 'cmd') so the full command path and every argument
# are captured. Fields $5..$NF are joined into one value so commands
Expand Down