User report 2026-05-25: launched 'npm run bot' fresh, MC server kicked
every login with "Игрок с данным никнеймом уже играет на сервере" and
the bot fell into a perpetual reconnect-then-kicked loop. Root cause:
a smoke-test supervisor from an earlier shell was still running in the
background, holding the pepa_bot session open. Two supervisors racing
on the same nickname is undefined behaviour from the server's side and
results in this exact failure mode.
Changes:
runtime/supervisor.js — acquires state/<host>/supervisor.pid before
spawning the child. If another supervisor is alive (kill -0 check), the
new one exits with a clear message telling the operator how to recover.
On SIGINT/SIGTERM/exit the lock is released; stale pidfiles are detected
when the recorded PID is no longer alive.
scripts/stop.sh — emergency cleanup helper:
- kills any supervisor or bot.js processes matching this repo
- removes pidfile + bot.sock
- reminds the operator to wait ~30s for the MC server to drop the old
session before re-launching
package.json — new `npm run stop` script.
Smoke-tested:
- first 'node runtime/supervisor.js' acquires lock, writes pid
- second call refuses with diagnostic message
- first SIGTERM ⇒ pidfile removed automatically
Co-authored-by: Yuriy Mayatnikov <mayatnikov@me.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
30 lines
1.1 KiB
Bash
Executable File
30 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Emergency stop: find any pepa-pi-bot supervisor/child processes plus any
|
|
# straggler TCP connection to the configured MC server, and terminate them.
|
|
# Useful when a smoke-test or a crashed instance left the nickname locked.
|
|
|
|
set -eu
|
|
|
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
echo "→ looking for supervisor + bot processes…"
|
|
PIDS=$(pgrep -f "$REPO_ROOT/runtime/(supervisor|bot)\.js" 2>/dev/null || true)
|
|
if [ -n "$PIDS" ]; then
|
|
echo " killing: $PIDS"
|
|
echo "$PIDS" | xargs kill -TERM 2>/dev/null || true
|
|
sleep 2
|
|
PIDS=$(pgrep -f "$REPO_ROOT/runtime/(supervisor|bot)\.js" 2>/dev/null || true)
|
|
if [ -n "$PIDS" ]; then
|
|
echo " still alive after TERM, sending KILL: $PIDS"
|
|
echo "$PIDS" | xargs kill -KILL 2>/dev/null || true
|
|
fi
|
|
else
|
|
echo " none found"
|
|
fi
|
|
|
|
echo "→ cleaning pidfile + bot.sock…"
|
|
find "$REPO_ROOT/state" -name "supervisor.pid" -delete 2>/dev/null || true
|
|
find "$REPO_ROOT/state" -name "bot.sock" -delete 2>/dev/null || true
|
|
|
|
echo "→ done. Wait ~30s for the MC server to drop the old session before re-launching."
|