-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-job-status-ctl
executable file
·98 lines (79 loc) · 1.53 KB
/
log-job-status-ctl
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
#!/bin/bash
#
# task-queue Start up Task Queue job logger
#
# chkconfig: 2345 95 05
# description: Log status of task queue jobs.
set -e
set -u
HOST=$(hostname -s)
if [[ $HOST =~ ^d ]]; then
ENV=dev
else
ENV=prod
fi
MY_CNF=/content/$ENV/rstar/etc/my-taskqueue.cnf
if [ ! -f "$MY_CNF" ]; then
echo "MySQL confile '$MY_CNF' doesn't exist." 1>&2
exit 1
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}
LOGDIR=${LOGDIR:-/content/$ENV/rstar/tmp/mdi/task-queue/logs}
MQHOST=${MQHOST:-localhost}
FOREGROUND=${FOREGROUND:-false}
RETVAL=0
get_pid() {
pgrep -f 'ruby.*log-job-status.rb' || true
}
start() {
PID=$(get_pid)
if [ -n "$PID" ]; then
echo "log-job-status already running with pid '$PID'" 1>&2
exit 1
fi
LOGFILE=$LOGDIR/$HOST/log-job-status.$HOST.log
CMD="$TQHOME/log-job-status.rb -m $MQHOST -c $MY_CNF -l $LOGFILE"
if [ "$FOREGROUND" != "true" ]; then
CMD="$CMD -d"
fi
if [ "$TQUSER" = "$(whoami)" ]; then
$CMD
else
if [ -f $LOGFILE ]; then
TQGROUP=$(id -gn $TQUSER)
chown $TQUSER:$TQGROUP $LOGFILE
fi
su -ls /bin/bash $TQUSER -c "$CMD"
fi
RETVAL=$?
}
stop() {
PID=$(get_pid)
[ -n "$PID" ] && kill $PID 2>/dev/null
RETVAL=$?
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 3
;;
esac
exit $RETVAL