-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.sh
More file actions
executable file
·127 lines (113 loc) · 3.09 KB
/
dev-server.sh
File metadata and controls
executable file
·127 lines (113 loc) · 3.09 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
#!/bin/bash
# Development server script for Spring Boot application with hot reloading
# Usage: ./dev-server.sh [start|stop|restart|status]
PID_FILE=".dev-server.pid"
LOG_FILE="logs/application-web.log"
start_server() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "Development server is already running (PID: $PID)"
return 1
else
rm -f "$PID_FILE"
fi
fi
echo "Starting development server with hot reloading..."
echo "Server will be available at: http://localhost:8080"
echo "LiveReload available at: http://localhost:35729"
echo "Logs are written to: $LOG_FILE"
# Start the server in background with development profile
nohup ./gradlew run -Dapp.mode=web -Dspring.profiles.active=dev > "$LOG_FILE" 2>&1 &
SERVER_PID=$!
echo $SERVER_PID > "$PID_FILE"
echo "Development server started (PID: $SERVER_PID)"
echo "Use './dev-server.sh stop' to stop the server"
echo "Use 'tail -f $LOG_FILE' to follow the logs"
}
stop_server() {
if [ ! -f "$PID_FILE" ]; then
echo "No PID file found. Server may not be running."
return 1
fi
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "Stopping development server (PID: $PID)..."
kill "$PID"
# Wait for process to stop
for i in {1..10}; do
if ! ps -p "$PID" > /dev/null 2>&1; then
break
fi
sleep 1
done
if ps -p "$PID" > /dev/null 2>&1; then
echo "Force killing server..."
kill -9 "$PID"
fi
rm -f "$PID_FILE"
echo "Development server stopped"
else
echo "Server process not found (PID: $PID)"
rm -f "$PID_FILE"
fi
}
server_status() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "Development server is running (PID: $PID)"
echo "Server URL: http://localhost:8080"
echo "LiveReload URL: http://localhost:35729"
else
echo "PID file exists but server is not running"
rm -f "$PID_FILE"
fi
else
echo "Development server is not running"
fi
}
restart_server() {
echo "Restarting development server..."
stop_server
sleep 2
start_server
}
case "${1:-start}" in
start)
start_server
;;
stop)
stop_server
;;
restart)
restart_server
;;
status)
server_status
;;
logs)
if [ -f "$LOG_FILE" ]; then
tail -f "$LOG_FILE"
else
echo "No log file found. Server may not be running."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status|logs}"
echo ""
echo "Commands:"
echo " start - Start the development server with hot reloading"
echo " stop - Stop the development server"
echo " restart - Restart the development server"
echo " status - Show server status"
echo " logs - Follow server logs"
echo ""
echo "Features:"
echo " - Automatic restart when Java classes change"
echo " - Live reload for static resources and templates"
echo " - Development-optimized configuration"
echo " - Background process management"
exit 1
;;
esac