-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.sh
More file actions
executable file
·99 lines (86 loc) · 2.56 KB
/
Copy pathqueue.sh
File metadata and controls
executable file
·99 lines (86 loc) · 2.56 KB
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
#!/bin/sh
#
# LJMS worker.
#
# ./queue.sh start start in the background
# ./queue.sh run run in the foreground (development)
# ./queue.sh stop finish the task in hand, then exit
# ./queue.sh status is it running?
#
# Safe to call "start" from cron every few minutes: an already-running worker
# makes it a no-op, so cron doubles as a restart-if-dead watchdog.
#
# Database credentials live in Processor.java, not here, one place to edit.
# Pass a node name only if you run more than one worker on this host.
LJMS_NODE="${LJMS_NODE:-}"
# Everything below is relative to the repository, and cron runs with cwd=$HOME,
# so anchor to this script's own directory or "start from cron" quietly starts
# nothing at all: -cp build would resolve under $HOME, java would exit with
# ClassNotFoundException, and the pid written below would already be dead.
cd "$(dirname "$0")" || exit 1
PIDFILE=logs/queue.pid
LOGFILE=logs/queue.out
CP_SEP=:
case "$(uname -s 2>/dev/null || echo unknown)" in
CYGWIN*|MINGW*|MSYS*) CP_SEP=';' ;;
esac
# build/ plus whatever is in lib/ (junit for tests, and your JDBC driver)
CP="build"
for jar in lib/*.jar; do
[ -f "$jar" ] && CP="${CP}${CP_SEP}${jar}"
done
[ -n "${CLASSPATH}" ] && CP="${CP}${CP_SEP}${CLASSPATH}"
JAVA_OPTS="${JAVA_OPTS:--Xms32m -Xmx256m}"
MAIN=org.ljms.Processor
mkdir -p logs
running() {
[ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null
}
case "${1:-start}" in
run)
exec java ${JAVA_OPTS} -cp "${CP}" ${MAIN} ${LJMS_NODE}
;;
start)
if running; then
echo "LJMS worker already running (pid $(cat "$PIDFILE"))"
exit 0
fi
nohup java ${JAVA_OPTS} -cp "${CP}" ${MAIN} ${LJMS_NODE} >> "$LOGFILE" 2>&1 &
echo $! > "$PIDFILE"
echo "LJMS worker started (pid $(cat "$PIDFILE")), output: $LOGFILE"
;;
stop)
if ! running; then
echo "LJMS worker is not running"
rm -f "$PIDFILE"
exit 0
fi
PID=$(cat "$PIDFILE")
# TERM triggers the shutdown hook: the loop exits after the task in hand.
kill "$PID"
echo "Stopping LJMS worker (pid $PID)..."
i=0
while kill -0 "$PID" 2>/dev/null; do
i=$((i+1))
if [ $i -gt 60 ]; then
echo "Still running after 60s - leaving it alone (kill -9 $PID to force)"
exit 1
fi
sleep 1
done
rm -f "$PIDFILE"
echo "Stopped"
;;
status)
if running; then
echo "LJMS worker running (pid $(cat "$PIDFILE"))"
else
echo "LJMS worker is not running"
exit 1
fi
;;
*)
echo "Usage: $0 {start|run|stop|status}"
exit 2
;;
esac