-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
·164 lines (142 loc) · 6.77 KB
/
Copy pathstop.sh
File metadata and controls
executable file
·164 lines (142 loc) · 6.77 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
#
# PromptAds AI – Stop Script
# Gracefully stops application services, then optionally infrastructure.
#
# Usage: ./stop.sh
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── Colours ──────────────────────────────────────────────────────────
G="\033[92m" # green
C="\033[96m" # cyan
Y="\033[93m" # yellow
R="\033[91m" # red
M="\033[95m" # magenta
B="\033[1m" # bold
D="\033[0m" # reset
DIM="\033[2m" # dim
W="\033[97m" # white
# ── Ports ────────────────────────────────────────────────────────────
PG_PORT=5433
QDRANT_PORT=6333
REDIS_PORT=6379
BE_PORT=8000
FE_PORT=3002
CHAT_PORT=3050
# ── Helper: kill processes on a port ─────────────────────────────────
kill_port() {
local port="$1"
local pids
pids=$(lsof -iTCP:"$port" -sTCP:LISTEN -t 2>/dev/null)
if [[ -n "$pids" ]]; then
echo "$pids" | xargs kill -9 2>/dev/null
return 0
fi
return 1
}
# ── Helper: check if port is in use ─────────────────────────────────
port_active() {
lsof -iTCP:"$1" -sTCP:LISTEN -t &>/dev/null
}
# ══════════════════════════════════════════════════════════════════════
# Phase 1: Stop Application Services
# ══════════════════════════════════════════════════════════════════════
echo ""
echo -e "${Y}${B}╔══════════════════════════════════════════════════════╗${D}"
echo -e "${Y}${B}║ Stopping PromptAds AI Services… ║${D}"
echo -e "${Y}${B}╚══════════════════════════════════════════════════════╝${D}"
echo ""
# ── Dashboard (port 3002) ────────────────────────────────────────────
echo -ne " ${B}Dashboard${D} ${DIM}:$FE_PORT${D} "
if kill_port $FE_PORT; then
echo -e "${G}✓ Stopped${D}"
else
echo -e "${DIM}not running${D}"
fi
# ── Conversational AI (port 3050) ────────────────────────────────────
echo -ne " ${B}Conversational AI${D} ${DIM}:$CHAT_PORT${D} "
if kill_port $CHAT_PORT; then
echo -e "${G}✓ Stopped${D}"
else
echo -e "${DIM}not running${D}"
fi
# ── Backend API (port 8000) ──────────────────────────────────────────
echo -ne " ${B}Backend API${D} ${DIM}:$BE_PORT${D} "
if kill_port $BE_PORT; then
echo -e "${G}✓ Stopped${D}"
else
echo -e "${DIM}not running${D}"
fi
echo ""
echo -e "${G}${B}╔══════════════════════════════════════════════════════╗${D}"
echo -e "${G}${B}║ ✦ Application services stopped! ║${D}"
echo -e "${G}${B}╚══════════════════════════════════════════════════════╝${D}"
echo ""
# ══════════════════════════════════════════════════════════════════════
# Phase 2: Ask about Infrastructure
# ══════════════════════════════════════════════════════════════════════
# Check which infra services are running
PG_RUNNING=false
QD_RUNNING=false
RD_RUNNING=false
port_active $PG_PORT && PG_RUNNING=true
port_active $QDRANT_PORT && QD_RUNNING=true
port_active $REDIS_PORT && RD_RUNNING=true
if ! $PG_RUNNING && ! $QD_RUNNING && ! $RD_RUNNING; then
echo -e " ${DIM}Infrastructure services are not running.${D}"
echo ""
exit 0
fi
echo -e " ${Y}Infrastructure still running:${D}"
echo ""
$PG_RUNNING && echo -e " ${B}PostgreSQL${D} ${DIM}:$PG_PORT${D}"
$QD_RUNNING && echo -e " ${B}Qdrant${D} ${DIM}:$QDRANT_PORT${D}"
$RD_RUNNING && echo -e " ${B}Redis${D} ${DIM}:$REDIS_PORT${D}"
echo ""
echo -e " ${W}Want to stop infrastructure too?${D}"
echo -e " ${DIM}Press ${Y}Ctrl+C${D}${DIM} → stop them │ Press ${C}Enter${D}${DIM} → keep them running${D}"
echo ""
# Trap Ctrl+C in this phase to stop infra
stop_infra() {
echo ""
echo ""
echo -e " ${Y}${B}Stopping infrastructure…${D}"
echo ""
if $PG_RUNNING; then
echo -ne " ${B}PostgreSQL${D} ${DIM}:$PG_PORT${D} "
# Try graceful pg_ctl stop first, fall back to kill
if command -v /opt/homebrew/opt/postgresql@16/bin/pg_ctl &>/dev/null; then
/opt/homebrew/opt/postgresql@16/bin/pg_ctl -D /opt/homebrew/var/postgresql@16 stop -m fast &>/dev/null && echo -e "${G}✓ Stopped${D}" || {
kill_port $PG_PORT && echo -e "${G}✓ Stopped${D}" || echo -e "${R}✗ Failed${D}"
}
else
kill_port $PG_PORT && echo -e "${G}✓ Stopped${D}" || echo -e "${R}✗ Failed${D}"
fi
fi
if $QD_RUNNING; then
echo -ne " ${B}Qdrant${D} ${DIM}:$QDRANT_PORT${D} "
kill_port $QDRANT_PORT && echo -e "${G}✓ Stopped${D}" || echo -e "${R}✗ Failed${D}"
fi
if $RD_RUNNING; then
echo -ne " ${B}Redis${D} ${DIM}:$REDIS_PORT${D} "
if command -v redis-cli &>/dev/null; then
redis-cli -p $REDIS_PORT shutdown &>/dev/null && echo -e "${G}✓ Stopped${D}" || {
kill_port $REDIS_PORT && echo -e "${G}✓ Stopped${D}" || echo -e "${R}✗ Failed${D}"
}
else
kill_port $REDIS_PORT && echo -e "${G}✓ Stopped${D}" || echo -e "${R}✗ Failed${D}"
fi
fi
echo ""
echo -e " ${G}${B}✦ Everything stopped. Goodbye!${D}"
echo ""
exit 0
}
trap stop_infra SIGINT
# Wait for Enter
read -r
# User pressed Enter → keep infra, just exit
echo -e " ${G}${B}✦ Infrastructure kept running. Goodbye!${D}"
echo ""
exit 0