-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
·88 lines (69 loc) · 1.94 KB
/
stop.sh
File metadata and controls
executable file
·88 lines (69 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
set -Eeuo pipefail
PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
MODE_FILE="${PROJECT_ROOT}/.p4lens_mode"
BACKEND_PID_FILE="${PROJECT_ROOT}/.backend.pid"
FRONTEND_PID_FILE="${PROJECT_ROOT}/.frontend.pid"
command_exists() {
command -v "$1" >/dev/null 2>&1
}
detect_compose() {
if command_exists docker; then
if docker compose version >/dev/null 2>&1; then
echo "docker compose"
return
fi
fi
if command_exists docker-compose; then
echo "docker-compose"
return
fi
echo ""
}
stop_local_process() {
local pid_file=$1
local label=$2
if [[ -f "${pid_file}" ]]; then
local pid
pid=$(cat "${pid_file}")
if ps -p "${pid}" >/dev/null 2>&1; then
echo "Stopping ${label} (PID: ${pid})..."
kill "${pid}" >/dev/null 2>&1 || true
fi
rm -f "${pid_file}"
fi
}
stop_docker_stack() {
local compose_bin
compose_bin="$(detect_compose)"
if [[ -z "${compose_bin}" ]]; then
echo "⚠️ Docker Compose not available, nothing to stop."
return
fi
echo "🛑 Bringing down Docker stack..."
pushd "${PROJECT_ROOT}" >/dev/null
${compose_bin} down -v --remove-orphans || true
popd >/dev/null
# Force-remove lingering containers if compose metadata was lost
if command_exists docker; then
docker rm -f p4lens-backend p4lens-frontend >/dev/null 2>&1 || true
fi
}
echo "🛑 Stopping P4Lens..."
MODE="local"
if command_exists docker; then
if docker ps --filter "name=p4lens-backend" --format "{{.ID}}" | grep -q . 2>/dev/null; then
MODE="docker"
fi
fi
if [[ -f "${MODE_FILE}" ]]; then
MODE=$(cat "${MODE_FILE}")
fi
if [[ "${MODE}" == "docker" ]]; then
stop_docker_stack
else
stop_local_process "${BACKEND_PID_FILE}" "backend"
stop_local_process "${FRONTEND_PID_FILE}" "frontend"
fi
rm -f "${MODE_FILE}"
echo "✅ P4Lens stopped"