-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
Β·173 lines (143 loc) Β· 4.56 KB
/
stop.sh
File metadata and controls
executable file
Β·173 lines (143 loc) Β· 4.56 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
#!/bin/bash
# GIS Map Application - Stop Script
# Author: Archil Odishelidze - DevSpace
# Description: Stops all services for the GIS mapping application
set -e
echo "πΊοΈ GIS Map Application - Stop Script"
echo "====================================="
echo ""
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to stop Spring Boot application
stop_spring_boot() {
echo "π Stopping Spring Boot application..."
# Check if PID file exists and process is running
if [ -f app.pid ]; then
local pid=$(cat app.pid)
if kill -0 "$pid" 2>/dev/null; then
echo " Stopping process with PID: $pid"
kill "$pid"
# Wait for graceful shutdown
local count=0
while kill -0 "$pid" 2>/dev/null && [ $count -lt 10 ]; do
echo " Waiting for graceful shutdown..."
sleep 1
((count++))
done
# Force kill if still running
if kill -0 "$pid" 2>/dev/null; then
echo " Force stopping process..."
kill -9 "$pid" || true
fi
fi
rm -f app.pid
fi
# Kill any remaining GisMapApplication processes
if command_exists pkill; then
pkill -f "GisMapApplication" || true
pkill -f "spring-boot:run" || true
fi
echo "β
Spring Boot application stopped"
}
# Function to stop Docker services
stop_docker_services() {
echo "π³ Stopping Docker services..."
if command_exists docker-compose; then
# Stop and remove containers
docker-compose down
echo "β
Docker services stopped"
else
echo "β οΈ docker-compose not found, skipping Docker services"
fi
}
# Function to clean up log files
cleanup_logs() {
echo "π§Ή Cleaning up log files..."
# Remove application logs
rm -f application.log
rm -f app.log
rm -f nohup.out
echo "β
Log files cleaned up"
}
# Function to show final status
show_final_status() {
echo ""
echo "π Final Status"
echo "==============="
# Check for any remaining processes
if command_exists pgrep; then
if pgrep -f "GisMapApplication" >/dev/null; then
echo "β οΈ Some GisMapApplication processes may still be running"
echo " PIDs: $(pgrep -f "GisMapApplication" | tr '\n' ' ')"
else
echo "β
No GisMapApplication processes running"
fi
fi
# Check Docker containers
if command_exists docker-compose; then
local running_containers=$(docker-compose ps -q)
if [ -n "$running_containers" ]; then
echo "β οΈ Some Docker containers may still be running:"
docker-compose ps --format "table {{.Name}}\t{{.Status}}"
else
echo "β
No Docker containers running"
fi
fi
echo ""
echo "π Ports should now be available:"
echo " - 8081 (Spring Boot)"
echo " - 8080 (GeoServer)"
echo " - 5432 (PostgreSQL)"
}
# Function to force stop everything
force_stop() {
echo "π₯ Force stopping all services..."
# Force kill Java processes
if command_exists pkill; then
pkill -9 -f "java.*GisMapApplication" || true
pkill -9 -f "mvn.*spring-boot:run" || true
fi
# Force stop Docker containers
if command_exists docker; then
docker kill $(docker ps -q --filter "name=postgis") 2>/dev/null || true
docker kill $(docker ps -q --filter "name=geoserver") 2>/dev/null || true
docker rm $(docker ps -aq --filter "name=postgis") 2>/dev/null || true
docker rm $(docker ps -aq --filter "name=geoserver") 2>/dev/null || true
fi
echo "β
Force stop completed"
}
# Main stop process
main() {
echo "π Stopping GIS Map Application..."
echo ""
# Check for force flag
if [ "$1" = "--force" ] || [ "$1" = "-f" ]; then
force_stop
cleanup_logs
show_final_status
echo ""
echo "π₯ All services force stopped!"
return
fi
# Graceful shutdown
stop_spring_boot
stop_docker_services
cleanup_logs
show_final_status
echo ""
echo "β
All services stopped successfully!"
echo ""
echo "π To start again, run: ./start.sh"
echo "π₯ For force stop, run: ./stop.sh --force"
}
# Handle script interruption
cleanup() {
echo ""
echo "π Stop script interrupted"
exit 1
}
trap cleanup INT TERM
# Run main function
main "$@"