diff options
| author | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-17 12:46:13 -0700 |
|---|---|---|
| committer | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-17 12:46:13 -0700 |
| commit | 1482422f2f5b236cdcdff4429ae06bb55dca4083 (patch) | |
| tree | 4653cb4986a8a138f84dbec934effb0d011751d3 /scripts/stop-stack.sh | |
Add stack start and stop scripts
Diffstat (limited to 'scripts/stop-stack.sh')
| -rwxr-xr-x | scripts/stop-stack.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/stop-stack.sh b/scripts/stop-stack.sh new file mode 100755 index 0000000..606de01 --- /dev/null +++ b/scripts/stop-stack.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +RUN_DIR="$ROOT_DIR/.run" + +BACKEND_PID_FILE="$RUN_DIR/backend.pid" +FRONTEND_PID_FILE="$RUN_DIR/frontend.pid" + +stop_process() { + local name="$1" + local pid_file="$2" + if [[ ! -f "$pid_file" ]]; then + echo "$name not running" + return + fi + + local pid + pid="$(cat "$pid_file")" + + if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then + kill "$pid" 2>/dev/null || true + for _ in {1..20}; do + if ! kill -0 "$pid" 2>/dev/null; then + break + fi + sleep 0.25 + done + if kill -0 "$pid" 2>/dev/null; then + kill -9 "$pid" 2>/dev/null || true + fi + echo "Stopped $name (PID $pid)" + else + echo "$name pid file was stale" + fi + + rm -f "$pid_file" +} + +stop_process "frontend" "$FRONTEND_PID_FILE" +stop_process "backend" "$BACKEND_PID_FILE" |
