-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.sh
executable file
·68 lines (60 loc) · 1.58 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
#!/bin/bash
usage="$0. Usage:\n
parameter 1: serv, app, all -- will launch either just the server, just the app, or everything\n
parameter 2: port number to bind the app to (optional). If negative, will only kill previous instances."
if [[ $# < 1 || $# > 2 ]]; then
echo -e $usage
exit 4
fi
w=6 # number of workers to launch
type=$1
if [[ $# > 1 ]]; then
port=$(($2+0))
else
port=5001
fi
if [[ $type != "all" && $type != "app" && $type != "serv" ]]; then
echo $usage
exit 4
fi
x=`whoami`
if [[ $type = "all" || $type = "serv" ]]; then
# create output directory
if [[ -d processing ]]; then
mkdir -p processing
fi
# kill old workers and server instance
for i in {1..10000}; do
pidf="/tmp/rqworker.$x.$i.pid"
if [ ! -f $pidf ]; then
break
fi
kill -9 `cat $pidf`
rm $pidf
done
pidf="/tmp/redis.$x.pid"
if [ -f $pidf ]; then
kill -9 `cat $pidf`
rm $pidf
fi
# launch server and worker instances
if [[ $port -gt 0 ]]; then
redis-server --daemonize yes --pidfile /tmp/redis.$x.pid --logfile /tmp/redis.$x.log
# redis-server --pidfile /tmp/redis.$x.pid --logfile /tmp/redis.$x.log &
for (( i=1; i<=$w; i++ )); do
rqworker --pid /tmp/rqworker.$x.$i.pid &
done
fi
fi
if [[ $type = "all" || $type = "app" ]]; then
# kill previous app
pidf="/tmp/gunicorn.$x.pid"
if [ -f $pidf ]; then
pkill -F $pidf
rm $pidf
fi
# launch app
if [[ $port -gt 0 ]]; then
gunicorn --pid $pidf --access-logfile /tmp/gunicorn.$x.log --daemon -w $w --graceful-timeout 1200 --timeout 1200 -b 0.0.0.0:$port MasterApp:app
fi
fi