-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop-frontend.sh
More file actions
executable file
·87 lines (72 loc) · 2.5 KB
/
stop-frontend.sh
File metadata and controls
executable file
·87 lines (72 loc) · 2.5 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
#!/bin/bash
# Stop the frontend dev server with robust cleanup
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FRONTEND_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PID_FILE="$FRONTEND_DIR/server.pid"
PORT=5173
echo "Stopping frontend server..."
# Step 1: Try to stop using PID file
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo " Found npm process with PID: $PID"
# Find child processes (the actual Vite server)
CHILD_PIDS=$(pgrep -P "$PID" 2>/dev/null || true)
if [ -n "$CHILD_PIDS" ]; then
echo " Found child process(es): $CHILD_PIDS"
fi
# Kill the parent process (npm)
kill "$PID" 2>/dev/null || true
# Wait for process to stop (max 5 seconds)
echo " Waiting for process to stop..."
for _ in {1..10}; do
if ! ps -p "$PID" > /dev/null 2>&1; then
echo " Parent process stopped gracefully"
break
fi
sleep 0.5
done
# Force kill parent if still running
if ps -p "$PID" > /dev/null 2>&1; then
echo " Force killing parent process (PID: $PID)..."
kill -9 "$PID" 2>/dev/null || true
sleep 0.5
fi
# Also kill any child processes that might be orphaned
if [ -n "$CHILD_PIDS" ]; then
for CHILD_PID in $CHILD_PIDS; do
if ps -p "$CHILD_PID" > /dev/null 2>&1; then
echo " Killing orphaned child process (PID: $CHILD_PID)..."
kill -9 "$CHILD_PID" 2>/dev/null || true
fi
done
fi
else
echo " PID $PID is not running"
fi
rm -f "$PID_FILE"
else
echo " No PID file found"
fi
# Step 2: Check if port is still in use and clean up
echo " Checking port $PORT..."
PORT_PID=$(lsof -ti:$PORT 2>/dev/null || true)
if [ -n "$PORT_PID" ]; then
echo " Port $PORT is still in use by PID(s): $PORT_PID"
echo " Killing processes using port $PORT..."
lsof -ti:$PORT | xargs kill -9 2>/dev/null || true
sleep 1
# Verify port is now free
PORT_PID=$(lsof -ti:$PORT 2>/dev/null || true)
if [ -n "$PORT_PID" ]; then
echo " Warning: Port $PORT is still in use by PID(s): $PORT_PID"
echo " You may need to manually kill these processes"
exit 1
else
echo " Port $PORT is now free"
fi
else
echo " Port $PORT is free"
fi
echo "Frontend server stopped successfully"