-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
·50 lines (40 loc) · 1.07 KB
/
stop.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.07 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
#!/bin/bash
# ============================================================
# Spring Boot Application Stop Script
# Usage: ./stop.sh
# ============================================================
APP_NAME="demo"
LOG_DIR="./logs"
PID_FILE="${LOG_DIR}/${APP_NAME}.pid"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; }
if [ ! -f "${PID_FILE}" ]; then
warn "PID file not found: ${PID_FILE}"
warn "${APP_NAME} may not be running."
exit 0
fi
PID=$(cat "${PID_FILE}")
if ! ps -p "${PID}" > /dev/null 2>&1; then
warn "${APP_NAME} (PID: ${PID}) is not running."
rm -f "${PID_FILE}"
exit 0
fi
info "Stopping ${APP_NAME} (PID: ${PID})..."
kill "${PID}"
for i in {1..15}; do
if ! ps -p "${PID}" > /dev/null 2>&1; then
break
fi
sleep 1
done
if ps -p "${PID}" > /dev/null 2>&1; then
warn "Force killing (PID: ${PID})..."
kill -9 "${PID}"
fi
rm -f "${PID_FILE}"
info "✓ ${APP_NAME} stopped."