-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstop-services.sh
More file actions
executable file
·78 lines (66 loc) · 1.94 KB
/
stop-services.sh
File metadata and controls
executable file
·78 lines (66 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
#!/bin/bash
# Microservices Stop Script
echo "🛑 Stopping Microservices..."
# Function to stop a service
stop_service() {
local service_name=$1
local pid_file="pids/${service_name}.pid"
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if ps -p $pid > /dev/null 2>&1; then
echo "🔄 Stopping $service_name (PID: $pid)..."
kill $pid
# Wait up to 10 seconds for graceful shutdown
for i in {1..10}; do
if ! ps -p $pid > /dev/null 2>&1; then
echo "✅ $service_name stopped gracefully"
break
fi
sleep 1
done
# Force kill if still running
if ps -p $pid > /dev/null 2>&1; then
echo "⚡ Force stopping $service_name..."
kill -9 $pid
fi
else
echo "⚠️ $service_name (PID: $pid) is not running"
fi
rm -f "$pid_file"
else
echo "⚠️ No PID file found for $service_name"
fi
}
# Stop services in reverse order
services=(
"product-service"
"user-service"
"auth-service"
"api-gateway"
"discovery-server"
)
for service in "${services[@]}"; do
stop_service "$service"
sleep 1
done
# Also try to kill any remaining Spring Boot processes
echo ""
echo "🔍 Checking for remaining Spring Boot processes..."
# Kill any remaining processes on known ports
ports=(8761 8080 8081 8082 8083)
for port in "${ports[@]}"; do
pid=$(lsof -ti:$port 2>/dev/null)
if [ ! -z "$pid" ]; then
echo "🔄 Killing process on port $port (PID: $pid)..."
kill -9 $pid 2>/dev/null || true
fi
done
echo ""
echo "✅ All microservices stopped!"
# Clean up log files option
read -p "🗑️ Remove log files? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -f logs/*.log
echo "🧹 Log files cleaned"
fi