-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkersctl
executable file
·125 lines (101 loc) · 2.03 KB
/
workersctl
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
122
123
124
125
#!/bin/bash
#
# task-queue Start up Task Queue
#
# chkconfig: 2345 99 01
# description: Task Queue runs jobs in parallel.
set -e
set -u
HOST=$(hostname -s)
if [[ $HOST =~ ^d ]]; then
ENV=dev
else
ENV=prod
fi
CONFIG_FILE=/content/$ENV/rstar/etc/task-queue.sysconfig
if [ -f "$CONFIG_FILE" ]; then
. $CONFIG_FILE
fi
TQHOME=${TQHOME:-/usr/local/dlib/task-queue}
TQUSER=${TQUSER:-rstar}
PIDFILE=${PIDFILE:-/var/lib/task-queue/taskqueueserver.pid}
LOGDIR=${LOGDIR:-/content/$ENV/rstar/tmp/mdi/task-queue/logs}
MQHOST=${MQHOST:-localhost}
USE_CGROUP=${USE_CGROUP:-true}
CGROUP_NAME=${CGROUP_NAME:-cpu:cpulimited}
FOREGROUND=${FOREGROUND:-false}
MIN_WORKERS=${MIN_WORKERS:-}
MAX_WORKERS=${MAX_WORKERS:-}
RETVAL=0
start() {
PIDS=$(pgrep -f 'ruby.*workers.rb' | paste -sd' ')
if [ -n "$PIDS" ]; then
echo "Task Queue already running with pids '$PIDS'" 1>&2
exit 1
fi
HOST_LOGDIR="$LOGDIR/$HOST"
LOGFILE=$HOST_LOGDIR/worker.$HOST.log
if [ ! -e "$HOST_LOGDIR" ]; then
mkdir -m 0755 $HOST_LOGDIR
fi
CMD="$TQHOME/workers.rb -m $MQHOST -l $LOGFILE -p $PIDFILE"
if [ "$FOREGROUND" = "true" ]; then
CMD="$CMD -f"
fi
if [ -n "$MIN_WORKERS" ]; then
CMD="$CMD -n $MIN_WORKERS"
fi
if [ -n "$MAX_WORKERS" ]; then
CMD="$CMD -x $MAX_WORKERS"
fi
if [ "$USE_CGROUP" = "true" ]; then
CMD="cgexec -g $CGROUP_NAME --sticky $CMD"
fi
if [ "$TQUSER" = "$(whoami)" ]; then
$CMD
else
TQGROUP=$(id -gn $TQUSER)
chown "${TQUSER}:${TQGROUP}" $HOST_LOGDIR
if [ -f $LOGFILE ]; then
chown "${TQUSER}:${TQGROUP}" $LOGFILE
fi
su -ls /bin/bash $TQUSER -c "$CMD"
fi
RETVAL=$?
}
stop() {
if [ -f $PIDFILE ]; then
kill `cat $PIDFILE`
RETVAL=$?
fi
}
restart() {
stop
sleep 5
start
}
reload() {
if [ -f $PIDFILE ]; then
kill -HUP `cat $PIDFILE`
RETVAL=$?
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: $0 {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit $RETVAL