-
Notifications
You must be signed in to change notification settings - Fork 9
/
bootstrap.sh
executable file
·64 lines (62 loc) · 2.09 KB
/
bootstrap.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
#!/bin/bash
BASEDIR=`pwd`
APP_NAME=$(basename ${BASEDIR})
MAIN_PY=main.py
case "$1" in
start)
procedure=`ps -ef | grep -w "${BASEDIR}" | grep -w "python" | grep -v "grep" | awk '{print $2}'`
if [ "${procedure}" = "" ];
then
echo "app start ..."
rm -f nohup.out
exec nohup python3 ${BASEDIR}/${MAIN_PY} --log-file-prefix ${APP_NAME}.log &
else
echo "${APP_NAME} was start"
fi
;;
run)
procedure=`ps -ef | grep -w "${BASEDIR}" |grep -w "python"| grep -v "grep" | awk '{print $2}'`
if [ "${procedure}" = "" ];
then
echo "${APP_NAME} start ..."
rm -f nohup.out
exec python3 ${BASEDIR}/${MAIN_PY}
else
echo "${APP_NAME} was start"
fi
;;
stop)
procedure=`ps -ef | grep -w "${BASEDIR}" | grep -w "python"| grep -v "grep" | awk '{print $2}'`
if [ "${procedure}" = "" ];
then
echo "${APP_NAME} was stop"
else
kill ${procedure}
sleep 2
arg_procedure=`ps -ef | grep -w "${BASEDIR}" |grep -w "python"| grep -v "grep" | awk '{print $2}'`
if [ "${arg_procedure}" = "" ];
then
echo "${APP_NAME}(${procedure}) stop success"
else
kill -9 ${arg_procedure}
echo "${APP_NAME} stop error"
fi
fi
rm -f nohup.out
;;
status)
procedure=`ps -ef | grep -w "${BASEDIR}" | grep -w "python" | grep -v "grep" | awk '{print $2}'`
if ["${procedure}" = ""];
then
echo "${APP_NAME} not run"
echo "info:"
echo nohup.out
else
echo "${APP_NAME} is running"
fi
;;
*)
echo "usage: $0 [start|run|stop|status]"
;;
esac
exit 0