forked from kingking888/sparrow_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gunicorn_start.sh
66 lines (54 loc) · 1.43 KB
/
gunicorn_start.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
#!/bin/sh
#service name
#项目的目录
#SERVICE_DIR=/opt/sparrow/sparrow_crawler
SERVICE_DIR=/Users/tinawang/sparrow/sparrow_crawler
#gunicorn的名字
SERVICE_NAME=gunicorn
#gunicorn的配置文件名
SERVICE_CONF=gunicorn.py
#虚拟环境的路径
#VIRTUAL_DIR=/opt/sparrow/sparrow_crawler/venv/bin/activate
VIRTUAL_DIR=/Users/tinawang/sparrow/sparrow_crawler
#pid存放的位置
PID=gunicorn\.pid
#项目启动入口
OBJECT_APP=sparrow_crawler.wsgi
RUN_ENV=test
export RUN_ENV
cd $SERVICE_DIR
#source $VIRTUAL_DIR
case "$1" in
start)
gunicorn $OBJECT_APP -c $SERVICE_DIR/$SERVICE_CONF >/dev/null 2>&1 &
echo $! > $SERVICE_DIR/$PID
echo "*** start $SERVICE_NAME ***"
;;
stop)
kill `cat $SERVICE_DIR/$PID`
rm -rf $SERVICE_DIR/$PID
echo "*** stop $SERVICE_NAME ***"
sleep 2
P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "*** $SERVICE_NAME process not exists or stop success ***"
else
echo "*** $SERVICE_NAME process pid is:$P_ID ***"
echo "*** begin kill $SERVICE_NAME process,kill is:$P_ID ***"
kill -9 $P_ID
fi
;;
restart)
$0 stop
sleep 2
$0 start
echo "*** restart $SERVICE_NAME ***"
;;
*)
## restart
$0 stop
sleep 2
$0 start
;;
esac
exit 0