Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a very specific problem and I've been fighting Upstart all night with no success.

I my particular case, I have a server with a bunch of PXE booted clients. The data for the clients is stored in MySQL. When I shut down the server, before anything happens, I need all the PXE clients to be turned off as well. In the old, sequential world of sysvinit this was a piece of cake: just put the remote shutdown script early in the sequence, before networking, portmap, nfs, mysql go down. This was ok even if it took 10 minutes for all the clients to go off (but usually 30 seconds would be enough).

With upstart I can't for the life of me get the clients to shutdown before the server. I managed to get the script executed before mysql went down, but that isn't enough, as it seems that the network and/or other support stuff that the PXE clients REALLY NEED goes down, so they NFS mounts go up in smoke and they never power off. They will power off as soon as the server is back up though.

The closest I got to getting what I want is this:

kill timeout 70

start on runlevel [016] and (stopping mysql or stopping portmap or stopping idmapd or stopping statd)

task

exec the-script-that-shuts-clients-down.sh

The script tells all the machines to shut down then keeps an eye on them (sending pings once a second), and only when either they're all down, or the script gets bored and gives up, should the server continue the shut down sequence.

Now, with Upstart, my script gets killed after about 7 seconds. Even with the 70 second timeout as above.

Ideally, I'd like to execute that script before anything else is triggered by the runlevel switch, but Google says I'm out of luck on this one. There's NO SEQUENTIAL mechanism in Upstart - even "backwards compatibility" rc is executed in parallel with the rest of the upstart services.

Any ideas on this one? I'm running Ubuntu 10.10.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I managed to solve my problem with this:

kill timeout 70

start on runlevel RUNLEVEL=[016] PREVLEVEL=[2345] and (starting rc RUNLEVEL=[016] or stopping mysql or stopping portmap or stopping idmapd or stopping statd)

task

exec the-script-that-shuts-clients-down.sh

Well, almost, because it looks like Upstart has a little bug that is specific to hooking on rc. At least in Ubuntu 10.10 it does. I don't have an 11.04 at hand to confirm it.

The work around right now looks like this:

In the-script-that-shuts-clients-down.sh, before exiting I do

touch /etc/init/my-job.conf

where my-job.conf contains the stuff above. So far it unstuck rc from start/starting everytime.

Another catch is that if I write starting rc rather than starting rc RUNLEVEL=[016] then upstart gets stuck on rc at boot too (and the same touch command unsticks it).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.