This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
scorebot.sh
executable file
·120 lines (102 loc) · 2.89 KB
/
scorebot.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
#!/usr/bin/env bash
port=8025
ip=0.0.0.0
pidfile=scorebot.pid
logfile=/var/log/scorebot2/scorebot_server.log
database=default
FILE=/x/local/scorebot/scorebot-service/scorebot_vars.sh
if [ -f ${FILE} ];
then
source ${FILE}
else
echo "Missing source server vars file: $FILE"
fi
# virtual environment, don't run if docker is not in use
# source $(dirname $0)/virtual_env.config
usage() {
cat <<EOF
usage:
$(basename $0) start [ ip:port ]
$(basename $0) restart [ ip:port ]
$(basename $0) stop
$(basename $0) status
EOF
exit 1
}
cd $(dirname $0)
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 on $(echo "$command" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}(:[0-9]{1,5})?\b" | head -1)
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 $(dirname $0) \
--module scorebot.wsgi:application \
--http-socket=${ip}:${port} \
--env DJANGO_SETTINGS_MODULE=scorebot.settings \
--static-map /static=$(dirname $0)/static \
--pidfile=${pidfile} \
--daemonize=${logfile} \
--stats $(dirname $0)/uwsgistats.socket \
--buffer-size 16383 \
--max-requests 1000 \
--master \
--workers 10 \
--logformat '%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)"'
./$(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
else
echo FAILED to stop $(basename $0 .sh)
exit 1
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