forked from Nader-gator/vast-pyworker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kill_server.sh
executable file
·48 lines (42 loc) · 1.34 KB
/
kill_server.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
#!/bin/bash
if [ -z "$SERVER_DIR" ]
then
current_cwd=$(pwd)
export SERVER_DIR="$current_cwd"
fi
# Define the target command
WATCH_CMD="python3 $SERVER_DIR/logwatch.py"
if [ -z "$MODEL_LAUNCH_CMD" ]
then
MODEL_LAUNCH_CMD="text-generation-launcher"
fi
AUTH_CMD="$SERVER_DIR/server.py"
# Get the process IDs (PIDs) of processes matching the target command
PIDS1=$(ps aux | grep "$WATCH_CMD" | grep -v grep | awk '{print $2}')
PIDS2=$(ps aux | grep "$MODEL_LAUNCH_CMD" | grep -v grep | awk '{print $2}')
PIDS4=$(ps aux | grep "$AUTH_CMD" | grep -v grep | awk '{print $2}')
# Check if any processes were found
while ! ([ -z "$PIDS1" ] && [ -z "$PIDS2" ] && [ -z "$PIDS3" ] && [ -z "$PIDS4" ])
do
# Loop through the PIDs and kill each process
for PID in $PIDS1; do
echo "Killing process $PID running: $WATCH_CMD"
kill "$PID"
done
for PID in $PIDS2; do
echo "Killing process $PID running: $MODEL_LAUNCH_CMD"
kill "$PID"
done
for PID in $PIDS4; do
echo "Killing process $PID running: $AUTH_CMD"
kill "$PID"
done
sleep 2
PIDS1=$(ps aux | grep "$WATCH_CMD" | grep -v grep | awk '{print $2}')
PIDS2=$(ps aux | grep "$MODEL_LAUNCH_CMD" | grep -v grep | awk '{print $2}')
PIDS4=$(ps aux | grep "$AUTH_CMD" | grep -v grep | awk '{print $2}')
done
if [ -e "$SERVER_DIR/infer.log" ]
then
rm "$SERVER_DIR/infer.log"
fi