Browse Source

Merge pull request #751 from savvyinsight/fix/stop-server-verify

fix: verify server actually stopped in stop-server.sh
Jesse Vincent 5 months ago
parent
commit
bd537d817d
1 changed files with 25 additions and 1 deletions
  1. 25 1
      skills/brainstorming/scripts/stop-server.sh

+ 25 - 1
skills/brainstorming/scripts/stop-server.sh

@@ -17,7 +17,31 @@ PID_FILE="${SCREEN_DIR}/.server.pid"
 
 if [[ -f "$PID_FILE" ]]; then
   pid=$(cat "$PID_FILE")
-  kill "$pid" 2>/dev/null
+
+  # Try to stop gracefully, fallback to force if still alive
+  kill "$pid" 2>/dev/null || true
+
+  # Wait for graceful shutdown (up to ~2s)
+  for i in {1..20}; do
+    if ! kill -0 "$pid" 2>/dev/null; then
+      break
+    fi
+    sleep 0.1
+  done
+
+  # If still running, escalate to SIGKILL
+  if kill -0 "$pid" 2>/dev/null; then
+    kill -9 "$pid" 2>/dev/null || true
+
+    # Give SIGKILL a moment to take effect
+    sleep 0.1
+  fi
+
+  if kill -0 "$pid" 2>/dev/null; then
+    echo '{"status": "failed", "error": "process still running"}'
+    exit 1
+  fi
+
   rm -f "$PID_FILE" "${SCREEN_DIR}/.server.log"
 
   # Only delete ephemeral /tmp directories