Since Ubuntu relies on upstart for some time now, I would like to use an upstart job to gracefully shutdown certain applications on system shutdown or reboot. It is essential that the system's shutdown or reboot is stalled until these applications are shut down.
The applications will be started manually on occasion, and on system shutdown should automatically be ended by a script (which I already have). Since the applications can't be ended reliably without (nearly all) other services running, ending the applications has to be done before the rest of the shutdown begins.
I think I can solve this by an upstart job which will be triggered on shutdown, but I am unsure which events I should use in which manner. So far, I have read the following (partly contradicting) statements:
- There is no general shutdown event in upstart
- Use a stanza like
start on starting shutdown
in the job definition - Use a stanza like
start on runlevel [06S]
in the job definition - Use a stanza like
start on starting runlevel [06S]
in the job definition - Use a stanza like
start on stopping runlevel [!06S]
in the job definition
From these recommendations, the following questions arise:
- Is there or is there not a general shutdown event in Ubuntu's upstart?
- What is the recommended way to implement a "shutdown hook"?
- When are the events runlevel [x] triggered; is this when having entered the runlevel or when entering the runlevel?
- Can we use something like
start on starting runlevel [x]
orstart on stopping runlevel [x]
? - What would be the best solution for my problem?
Thank you very much
start on starting ...
It doesn't make much sense to have my shutdown hook stop on anything.start on starting rc RUNLEVEL=[016]
would make much more sense. And maybe atask
thrown in there to ensure it can complete before other things run. – Tejay Cardon Apr 14 '15 at 19:53