/
wait-for-job-state.conf
60 lines (50 loc) · 1.54 KB
/
wait-for-job-state.conf
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
author "Clint Byrum <clint.byrum@canonical.com>"
description "Waiting for state passively"
task
normal exit 2
stop on started $WAIT_FOR or stopped $WAIT_FOR
# this is wait-for-state mainly, but it does not start $WAIT_FOR
# as this kill the start conditions of $WAIT_FOR (steffenbpunkt@gmail.com)
# These are all arguments for use influencing how this job waits
env TIMEOUT=30
env MANUAL_OVERRIDE="N"
env WAIT_FOREVER="N"
env WAIT_STATE="started"
env TARGET_GOAL="start"
# Required args w/ no sensible default, the tests at the beginning of
# the script are just to guard against WAITER="" or WAIT_FOR="", as the
# instance line will fail if they are not set, since they have no env
instance $WAITER$WAIT_FOR
script
test -n "$WAIT_FOR" || exit 1
test -n "$WAITER" || exit 1
# We don't want to override the manual stanza
# XXX: initctl show-config should share manual w/ us too
case $MANUAL_OVERRIDE in
N|n|0)
if grep -q "^\s*manual\s*$" /etc/init/$WAIT_FOR.conf ; then
exit 0
fi
;;
esac
if [ "$WAIT_STATE" = "stopped" ] ; then
TARGET_GOAL="stop"
fi
# Already running/stopped?
status $WAIT_FOR | grep -q "$TARGET_GOAL/$WAIT_STATE" && exit 0
# upstart will kill this shell on started/stopped $WAIT_FOR
while sleep $TIMEOUT ; do
case $WAIT_FOREVER in
N|n|0)
exit 100
;;
Y|y|1)
;;
*)
exit 1
;;
esac
done
# Very strange, sleep returned non-zero?
exit 1
end script