-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe_start.sh
More file actions
62 lines (55 loc) · 1.66 KB
/
safe_start.sh
File metadata and controls
62 lines (55 loc) · 1.66 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
app_name=API-Router
router_host=$1
router_port=$2
router_db=$3
input() {
if [[ $router_host == "" ]];then
router_host=192.168.100.126
fi
if [[ $router_port == "" ]];then
router_port=9010
fi
if [[ $router_db == "" ]];then
router_db=test
fi
}
router_stop() {
app=$( ps -ef | grep python | grep server.py | grep ${router_host} | grep ${router_port} | awk '{print $2}' )
if [[ $app != "" ]];then
exit_app="kill -9 ${app}"
echo "Stop Command ( router ) : "${exit_app}
$exit_app
else
echo "Not Found application. ( router )"
fi
}
uvicorn_stop() {
uvicorn=$( netstat -nlp | grep ${router_host}':'${router_port} | awk '{print $7}' | tr "/" "\n" )
if [[ $uvicorn != "" ]];then
for i in $uvicorn
do
if [[ ${i} == *python* ]];then
continue
fi
exit_uvicorn="kill -9 ${i}"
echo "Stop Command ( uvicorn ) : "${exit_uvicorn}
$exit_uvicorn
done
else
echo "Not Found application. ( uvicorn )"
fi
}
router_start() {
source_path="$( cd "$( dirname "$0" )" && pwd -P )"
router_exec="nohup python3 ${source_path}/server.py --host ${router_host} --port ${router_port} --db_type ${router_db} 1> /dev/null 2>&1 &"
echo "Start Command : ${router_exec}"
nohup python3 ${source_path}/server.py --host ${router_host} --port ${router_port} --db_type ${router_db} 1> /dev/null 2>&1 &
}
echo "########## Safe Start (${app_name}) ##########"
echo "========== STOP ${app_name} =========="
input
router_stop
sleep 2
uvicorn_stop
echo "========== START ${app_name} =========="
router_start