-
Notifications
You must be signed in to change notification settings - Fork 154
/
restart.sh
executable file
·45 lines (37 loc) · 1.19 KB
/
restart.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
#!/bin/bash
if [ -e pid.stamp ]
then
echo 'kill old process...'
kill -9 `cat pid.stamp`;
fi
#nohup gradio webui.py & echo $! > pid.stamp
nohup gradio app.py & echo "pid: $!"
echo 'restarting...'
sleep 5
env_file="./.env"
py_environment=$(grep "^PY_ENVIRONMENT=" "$env_file" | cut -d '=' -f 2)
# Get the TCP port number from the configure file
libai_tcp_port=$(grep "ui_port:" "./config/config-$py_environment.yaml" | head -n 1 | awk '{print $2}')
# Check if the tcp_port variable is set
if [ -z "$libai_tcp_port" ]
then
echo "Warning: libai_tcp_port environment variable is not set."
# exit 1
fi
while [ 1 ]; do
# Find the process ID associated with the specified TCP port
pid=$(netstat -nap | grep ":$libai_tcp_port " | awk '{print $7}' | head -n 1 | cut -d '/' -f 1)
# Check if a process ID is found
if [ -n "$pid" ] && [ "$pid" != "-" ]
then
echo "Process ID associated with TCP port $libai_tcp_port: $pid"
# Dump the process ID to a local file named pid.stamp
echo "$pid" > pid.stamp
echo "Process ID dumped to pid.stamp"
break
else
echo "No process found listening on TCP port $libai_tcp_port"
echo "continue waiting 3 seconds... "
sleep 3
fi
done