forked from xuke1668/pyapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
98 lines (87 loc) · 2.27 KB
/
run.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#set -x
source /etc/profile
function get_pid(){
echo `ps aux|grep "${UWSGI} --uid "|grep ":${port} "|grep -v "grep"|awk '{print $2}' |xargs`
}
function Status(){
pid=`get_pid`
if [ "X$pid" != "X" ];then
echo "uwsgi-${app} is running![$pid]"
else
echo "uwsgi-${app} is not running!"
fi
}
function Start(){
pid=`get_pid`
if [ "X$pid" != "X" ];then
echo "uwsgi-${app} is running![$pid]"
return
else
${UWSGI} --uid ${USER} -s ${host}:${port} --gevent 1000 -M -t 30 --pidfile ${pidfile} --chdir ${cur_dir} -w myapp:flask_app -d ${logfile} --logformat '"%(ltime)" "%(addr)" "%(uagent)" "%(method) %(uri)" %(status) %(rsize)B %(msecs)ms'
fi
sleep 1
pid=`get_pid`
if [ "X$pid" = "X" ];then
echo "Start uwsgi-${app} failed"
exit 1
else
echo "Start uwsgi-${app} success![$pid]"
fi
}
function Stop(){
pid=`get_pid`
if [ "X$pid" = "X" ];then
echo "uwsgi-${app} is not running!"
else
${UWSGI} --uid ${USER} --stop ${pidfile}
if [ $? -ne 0 ];then
echo "Stop uwsgi-${app} failed![$pid]"
exit 1
else
echo "Stop uwsgi-${app} success!"
fi
fi
}
function Reload(){
pid=`get_pid`
if [ "X$pid" = "X" ];then
echo "uwsgi-${app} is not running!"
Start
else
${UWSGI} --uid ${USER} --reload ${pidfile}
if [ $? -ne 0 ];then
echo "Reload uwsgi-${app} failed![$pid]"
exit 1
else
pid=`get_pid`
if [ "X$pid" != "X" ];then
echo "Reload uwsgi-${app} success![$pid]"
else
echo "Reload uwsgi-${app} failed!"
exit 1
fi
fi
fi
}
cur_dir="$(cd `dirname "$0"` && pwd)"
UWSGI='/data/apps/py36_flask/bin/uwsgi'
USER='uwsgi'
app='web'
host='127.0.0.1'
port='8890'
pidfile="/var/run/uwsgi-${app}.pid"
logfile="/var/log/uwsgi-${app}.log"
if [ "${1,,}" = "status" ]; then
Status
elif [ "${1,,}" = "start" ]; then
Start
elif [ "${1,,}" = "stop" ];then
Stop
elif [ "${1,,}" = "reload" ];then
Reload
elif [ "${1,,}" = "restart" ];then
Stop && sleep 1 && Start
else
echo -e "Usages:\n\tbash $0 [status|start|stop|reload|restart]"
fi