← Back to SKILL.md1#!/usr/bin/env bash2# Gracefully stop the OmniVoice backend bound to 127.0.0.1:3900.3#4# Exit codes:5# 0 stopped (or never running)6# 1 process(es) still bound to 3900 after SIGTERM + SIGKILL escalation7# 2 permission denied killing a bound process (EPERM — try sudo or a different account)8 9set -euo pipefail10 11# Helper: discover current PIDs bound to 3900 (recomputed each time to avoid stale data)12current_pids() {13 lsof -nP -iTCP:3900 -sTCP:LISTEN -t 2>/dev/null || true14}15 16PIDS="$(current_pids)"17if [ -z "$PIDS" ]; then18 echo "no listener on 3900"19 exit 020fi21 22# SIGTERM phase — let processes shut down cleanly. Surface EPERM loudly so the user23# knows when they can't actually stop the backend (wrong user, sandboxed process, etc.).24EPERM_HIT=025for pid in $PIDS; do26 echo "kill -TERM $pid"27 if ! kill -TERM "$pid" 2>/tmp/.omnivoice-kill-err; then28 if grep -qi 'permitted\|denied' /tmp/.omnivoice-kill-err 2>/dev/null; then29 echo " ✗ EPERM — cannot signal PID $pid (different user / sandboxed)" >&230 EPERM_HIT=131 elif grep -qi 'no such process' /tmp/.omnivoice-kill-err 2>/dev/null; then32 : # benign — process already gone33 else34 cat /tmp/.omnivoice-kill-err >&2 || true35 fi36 fi37done38rm -f /tmp/.omnivoice-kill-err39 40if [ "$EPERM_HIT" -eq 1 ]; then41 echo "✗ at least one bound process refused SIGTERM (permission denied)." >&242 echo " Try \`sudo $(realpath "$0")\` or stop the owning process manually." >&243 exit 244fi45 46# Wait up to 10s for graceful exit (poll lsof, not the captured PID list — PIDs may have been47# reaped or recycled by the kernel during this window).48for i in $(seq 1 5); do49 sleep 250 if [ -z "$(current_pids)" ]; then51 echo "stopped"52 exit 053 fi54done55 56# Escalate to SIGKILL on whatever is currently bound (re-query — don't trust stale PIDs).57echo "still running after 10s — escalating to SIGKILL" >&258PIDS="$(current_pids)"59for pid in $PIDS; do kill -KILL "$pid" 2>/dev/null || true; done60sleep 161 62# Verify the port is actually free now. If it's still held, the script failed its job.63if [ -n "$(current_pids)" ]; then64 echo "✗ port 3900 STILL bound after SIGKILL:" >&265 lsof -nP -iTCP:3900 -sTCP:LISTEN 2>&1 | head -3 >&266 exit 167fi68 69echo "stopped (after SIGKILL)"70exit 071