-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop-dev.sh
executable file
·87 lines (75 loc) · 2.29 KB
/
stop-dev.sh
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
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to check if a port is in use
check_port() {
local port=$1
if lsof -i :$port > /dev/null; then
return 0
else
return 1
fi
}
# Store the script's directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PID_DIR="${SCRIPT_DIR}/storage/pids"
LARAVEL_PID_FILE="${PID_DIR}/laravel.pid"
VITE_PID_FILE="${PID_DIR}/vite.pid"
# Function to stop a process by PID file
stop_process() {
local pid_file=$1
local process_name=$2
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if ps -p "$pid" > /dev/null; then
print_status "$YELLOW" "Stopping $process_name (PID: $pid)..."
kill "$pid"
# Wait for process to stop
for i in {1..5}; do
if ! ps -p "$pid" > /dev/null; then
break
fi
sleep 1
done
# Force kill if still running
if ps -p "$pid" > /dev/null; then
print_status "$YELLOW" "Force stopping $process_name..."
kill -9 "$pid"
fi
fi
rm "$pid_file"
fi
}
# Stop Laravel server
stop_process "$LARAVEL_PID_FILE" "Laravel development server"
# Stop Vite server
stop_process "$VITE_PID_FILE" "Vite development server"
# Check for any remaining processes on the ports
if check_port 8000; then
print_status "$YELLOW" "Cleaning up remaining process on port 8000..."
lsof -ti :8000 | xargs kill -9 > /dev/null 2>&1
fi
if check_port 5173; then
print_status "$YELLOW" "Cleaning up remaining process on port 5173..."
lsof -ti :5173 | xargs kill -9 > /dev/null 2>&1
fi
# Final verification
if ! check_port 8000 && ! check_port 5173; then
print_status "$GREEN" "Development servers stopped successfully!"
else
print_status "$RED" "Warning: Some processes may still be running"
print_status "$YELLOW" "Please check manually with: lsof -i :8000 and lsof -i :5173"
fi
# Clean up PID directory if empty
if [ -d "$PID_DIR" ] && [ -z "$(ls -A $PID_DIR)" ]; then
rmdir "$PID_DIR"
fi