forked from paypal/scorebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscorebot_gcp.sh
executable file
·121 lines (105 loc) · 2.84 KB
/
scorebot_gcp.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
homedir=/x/local/scorebot/scorebot-service
pidfile=$(basename $0 .sh).pid
logfile=/var/log/scorebot2/$(basename $0 .sh)_server.log
database=default
#Environment variable files
varfile=scorebot_vars.sh
if [ -f ${varfile} ];
then
source ${varfile}
else
echo "Missing source server vars file: $varfile"
fi
source ${homedir}/virtual_env.config
usage() {
cat <<EOF
usage:
$(basename $0) start
$(basename $0) restart
$(basename $0) stop
$(basename $0) status
EOF
exit 1
}
cd ${homedir}
descendent_pids() {
for ppid in $* ; do
echo ${ppid}
descendent_pids $(ps ax -o ppid,pid | awk "\$1 == $ppid { print \$2 }")
done
}
status() {
for pid in $(cat ${pidfile}) ; do
command="$(ps -o command ${pid} | tail -1)"
if [[ "$command" == *uwsgi\ * ]]; then
echo $(basename $0 .sh) is running through uwsgi.sock for nginx integration
else
echo ProcessID ${pid} invalid. Run stop for clean up
fi
done
}
case "$1" in
start)
if [ -s ${pidfile} ]; then
echo $(basename $0 .sh) CANNOT be started
status
exit 1
fi
echo Starting up $(basename $0 .sh)
./manage.py migrate --database=${database} --noinput || exit 1
./manage.py collectstatic --noinput || exit 1
uwsgi \
${VIRTENV} \
--chdir=${homedir} \
--module=scorebot.wsgi:application \
--env DJANGO_SETTINGS_MODULE=scorebot.settings \
--env HTTPS=on \
--env wsgi.url_scheme=https \
--static-map /static=${homedir}/static \
--pidfile=${pidfile} \
--daemonize=${logfile} \
--stats=${homedir}/uwsgistats.socket \
--buffer-size=16383 \
--max-requests=1000 \
--master \
--workers=10 \
--uwsgi-socket=${homedir}/uwsgi.sock \
--chmod-socket=666 \
--vacuum \
--logformat='%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)"'
sleep 2
./$(basename $0) status
;;
stop)
if [ -s ${pidfile} ]; then
echo Shutting down $(basename $0 .sh)
uwsgi --stop ${pidfile}
sleep 5
if ./$(basename $0) status > /dev/null ; then
rm -f ${pidfile}
exit 0
fi
else
echo $(basename $0 .sh) does NOT appear to be running
exit 1
fi
;;
restart)
if ./$(basename $0) status > /dev/null ; then
./$(basename $0) stop
fi
./$(basename $0) start ${2:-$ip:$port}
;;
status)
if [ -s ${pidfile} ]; then
status
exit 0
fi
echo $(basename $0 .sh) is NOT running
exit 1
;;
*)
usage
;;
esac