Upstart wait job

March 2011


I got this from the portmap-wait job by Clint Byrum. If an upstart job needs to wait for another (e.g. ssh), we can create a special wait job:

Example 1.  A wait job for ssh

# lwp-ssh-wait - wait-service for ssh
description     "wait-service for ssh"

#
# Long description:
# This job wil hang forever unless ssh comes up
# Jobs wanting to wait for ssh can call this one, like so:
#
# start lwp-ssh-wait WAITER=otherjob
#

# Have this job killed when ssh is started (or stopped)
stop on started ssh or stopped ssh 1

author "Jurjen Bokma <j.bokma@rug.nl>"

# If we finish with status 2 (by being killed), that is ok
normal exit 2
task
instance $WAITER 2

script
status ssh|grep -q 'start/running' && exit 0 3
start ssh || true 4 5
while sleep 1800 ; do :; done 1
end script
      

3

If the job waited for -i.c. ssh- is started already, the wait job exits immediately.

4

We may or may not want to do this: start the job being waited for from the wait job.

5

I any case, starting ssh will wait until ssh is actually started.

1

This will put the job to indefinite sleep, but the stop condition will have upstart kill the job anyway.

2

Having instances of the job makes it possible for multiple other jobs to call the wait job and still all block until ssh is running.


Now another job, one that needs to wait for ssh to be present, can call the wait job like this:

Example 2.  A job that calls the wait job


[Note]Note

Lwp-do-something else could also be made to wait for ssh by adding

and started ssh

to the start conditions, but that would have the side effect of making rsyslog wait for ssh, which may be unwanted, see