-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstop-dev.sh
More file actions
executable file
·209 lines (180 loc) · 6.46 KB
/
Copy pathstop-dev.sh
File metadata and controls
executable file
·209 lines (180 loc) · 6.46 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PID_DIR="$PROJECT_ROOT/.pids"
LOG_DIR="$PROJECT_ROOT/.logs"
# Parse arguments
STOP_DOCKER=true
CLEAN_VOLUMES=false
CLEAN_LOGS=false
CLEAN_VENV=false
FORCE=false
usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Stop FullRestore development services"
echo ""
echo "Options:"
echo " --apps-only Stop application processes only (keep Docker services running)"
echo " --clean-volumes Also remove Docker volumes (WARNING: deletes database data)"
echo " --clean-logs Also remove log files"
echo " --clean-venv Also remove the backend virtual environment"
echo " --force Force kill processes that don't respond to SIGTERM"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Stop everything"
echo " $0 --apps-only # Stop apps, keep PostgreSQL/Redis/MinIO running"
echo " $0 --clean-volumes # Stop everything and delete all data"
echo " $0 --clean-venv # Stop everything and remove Python virtual environment"
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
--apps-only)
STOP_DOCKER=false
shift
;;
--clean-volumes)
CLEAN_VOLUMES=true
shift
;;
--clean-logs)
CLEAN_LOGS=true
shift
;;
--clean-venv)
CLEAN_VENV=true
shift
;;
--force)
FORCE=true
shift
;;
-h|--help)
usage
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
usage
;;
esac
done
echo -e "${BLUE}=== FullRestore Development Shutdown ===${NC}"
# Stop application processes from PID files
stop_app_processes() {
echo -e "\n${BLUE}[1/3] Stopping application processes...${NC}"
if [ ! -d "$PID_DIR" ] || [ -z "$(ls -A "$PID_DIR" 2>/dev/null)" ]; then
echo -e "${YELLOW}No PID files found in $PID_DIR${NC}"
else
for pidfile in "$PID_DIR"/*.pid; do
if [ -f "$pidfile" ]; then
local pid=$(cat "$pidfile")
local name=$(basename "$pidfile" .pid)
if kill -0 "$pid" 2>/dev/null; then
echo -e " Stopping $name (PID: $pid)..."
kill "$pid" 2>/dev/null || true
# Wait for graceful shutdown
local count=0
while kill -0 "$pid" 2>/dev/null && [ $count -lt 10 ]; do
sleep 0.5
count=$((count + 1))
done
# Force kill if still running and --force was specified
if kill -0 "$pid" 2>/dev/null; then
if [ "$FORCE" = true ]; then
echo -e " ${YELLOW}Force killing $name...${NC}"
kill -9 "$pid" 2>/dev/null || true
else
echo -e " ${YELLOW}$name still running, use --force to kill${NC}"
fi
else
echo -e " ${GREEN}$name stopped${NC}"
fi
else
echo -e " ${YELLOW}$name already stopped${NC}"
fi
rm -f "$pidfile"
fi
done
fi
# Also try to find and kill any orphaned processes
echo -e "\n${YELLOW}Checking for orphaned processes...${NC}"
# Kill uvicorn processes for this project
local uvicorn_pids=$(pgrep -f "uvicorn src.api:app" 2>/dev/null || true)
if [ -n "$uvicorn_pids" ]; then
echo -e " Stopping orphaned uvicorn processes..."
echo "$uvicorn_pids" | xargs kill 2>/dev/null || true
fi
# Kill celery processes for this project
local celery_pids=$(pgrep -f "celery -A celery_config" 2>/dev/null || true)
if [ -n "$celery_pids" ]; then
echo -e " Stopping orphaned celery processes..."
echo "$celery_pids" | xargs kill 2>/dev/null || true
fi
# Kill Next.js dev server
local next_pids=$(pgrep -f "next dev" 2>/dev/null || true)
if [ -n "$next_pids" ]; then
echo -e " Stopping orphaned Next.js processes..."
echo "$next_pids" | xargs kill 2>/dev/null || true
fi
}
# Stop Docker services
stop_docker_services() {
echo -e "\n${BLUE}[2/3] Stopping Docker services...${NC}"
cd "$PROJECT_ROOT/infrastructure/docker"
if [ "$CLEAN_VOLUMES" = true ]; then
echo -e "${RED}WARNING: Removing Docker volumes (all data will be lost)${NC}"
docker compose down -v
echo -e "${GREEN}Docker services stopped and volumes removed${NC}"
else
docker compose down
echo -e "${GREEN}Docker services stopped (volumes preserved)${NC}"
fi
}
# Clean up logs and virtual environment
cleanup() {
echo -e "\n${BLUE}[3/3] Cleaning up...${NC}"
if [ "$CLEAN_LOGS" = true ] && [ -d "$LOG_DIR" ]; then
echo -e " Removing log files..."
rm -rf "$LOG_DIR"
echo -e "${GREEN} Log files removed${NC}"
fi
if [ "$CLEAN_VENV" = true ] && [ -d "$PROJECT_ROOT/backend/.venv" ]; then
echo -e " Removing backend virtual environment..."
rm -rf "$PROJECT_ROOT/backend/.venv"
echo -e "${GREEN} Virtual environment removed${NC}"
fi
# Clean up PID directory
if [ -d "$PID_DIR" ]; then
rm -rf "$PID_DIR"
fi
}
# Execute shutdown
stop_app_processes
if [ "$STOP_DOCKER" = true ]; then
stop_docker_services
else
echo -e "\n${YELLOW}[2/3] Skipping Docker services (--apps-only specified)${NC}"
echo -e "${YELLOW} Docker services still running: postgres, redis, minio${NC}"
fi
cleanup
# Final status
echo -e "\n${GREEN}=== Shutdown complete ===${NC}"
if [ "$STOP_DOCKER" = false ]; then
echo -e "\n${BLUE}Docker services still running:${NC}"
cd "$PROJECT_ROOT/infrastructure/docker"
docker compose ps 2>/dev/null || echo -e "${YELLOW} (docker compose ps failed)${NC}"
fi
if [ "$CLEAN_VOLUMES" = true ]; then
echo -e "\n${YELLOW}Note: All Docker data was deleted. Run ./start-dev.sh to reinitialize.${NC}"
fi
if [ "$CLEAN_VENV" = true ]; then
echo -e "\n${YELLOW}Note: Virtual environment was deleted. Run ./start-dev.sh to recreate.${NC}"
fi