#!/bin/sh APP="$(cd "$(dirname "$0")/.." && pwd)" GUNICORN="$APP/backend/.venv/bin/gunicorn" if [ -f "$APP/app.pid" ]; then kill "$(cat "$APP/app.pid")" 2>/dev/null && echo "stopped $(cat "$APP/app.pid")" rm -f "$APP/app.pid" fi # The master's workers do not always go with it, and a surviving worker keeps # :8124 bound — which looks exactly like a healthy start that serves nothing. # # `ps | grep` rather than pgrep: DSM does not ship pgrep, so the original # check failed with 127 on every iteration — never matching the `|| exit 0` # early return, always burning the full 15 seconds, and never actually # confirming anything. alive() { ps -eo args 2>/dev/null | grep -q "^$GUNICORN"; } i=0 while [ $i -lt 15 ]; do alive || exit 0 sleep 1 i=$((i + 1)) done pkill -9 -f "$GUNICORN" 2>/dev/null echo "force-stopped leftover workers"