fix: increase sleep time

This commit is contained in:
Julian Sommer
2026-03-19 15:02:50 +10:00
parent 857cbd75ac
commit ea8700df99
+21 -17
View File
@@ -73,31 +73,35 @@ if is_multinode && [ -z "${SPINIFEX_FORCE_LOCAL_STOP:-}" ] && [ -z "${1:-}" ]; t
exec $PROJECT_ROOT/bin/spx admin cluster shutdown
fi
# Function to stop a service. Uses `spx service stop` (graceful, kills the
# actual Go process) and falls back to the shell-wrapper PID file if the
# binary isn't available.
# Function to stop a service. Sends SIGTERM and waits for the process to exit
# so resources (ports, DB locks) are fully released before returning.
stop_service() {
local name="$1"
local pidpath="$2"
echo "🛑 Stopping $name..."
local rc=0
if [ -x "$PROJECT_ROOT/bin/spx" ]; then
$PROJECT_ROOT/bin/spx service "$name" stop || rc=$?
elif [ -n "$pidpath" ]; then
kill -SIGTERM $(cat "$pidpath/$name.pid" 2>/dev/null) 2>/dev/null || rc=$?
local pid
pid=$(cat "$pidpath/$name.pid" 2>/dev/null) || { echo "⚠️ No PID file for $name"; return 1; }
kill -SIGTERM "$pid" 2>/dev/null || { rm -f "$pidpath/$name.pid"; echo "✅ $name already stopped"; echo ""; return 0; }
# Wait for process to fully exit (up to 15s) so ports/locks are released
local checks=0
while kill -0 "$pid" 2>/dev/null; do
sleep 1
fi
if [[ $rc -ne 0 ]]; then
echo "⚠️ Failed to stop $name (exit code $rc)"
return 1
else
echo "✅ $name stopped"
echo ""
fi
checks=$((checks + 1))
if [ "$checks" -ge 15 ]; then
echo " Force killing $name..."
kill -9 "$pid" 2>/dev/null || true
sleep 1
break
fi
done
rm -f "$pidpath/$name.pid"
echo "✅ $name stopped"
echo ""
}
# Stop services in reverse order