Sometimes my server is shut down via an ACPI shutdown, and I've managed to get my process to gracefully shut down. However, my process (Job A) relies on another process (Job B) during its graceful shutdown, so I now want to make sure that Job B doesn't stop until Job A has stopped.

Both processes are Upstart jobs, so I've tried doing this by adding this to Job B's /etc/init file:

# Don't stop until job A stops
pre-stop script
    while true
        status A | grep -q "stop/waiting" && exit 0
        sleep 1
end script

This doesn't seem to work; when I shutdown my server via ACPI shutdown, job B usually shuts down before job A, such that job A spits out error messages about job B not being up.

Is there something wrong with my script? Is there another approach I should be taking? Or is it not possible to do what I want with Upstart?

Related question: How do I stop a job before its dependencies?

1 Answer 1


You can use these options within job A:

  • Stop before depended-upon service

    stop on stopping B
  • Start after depended-upon service

    start on started B

Reference: http://upstart.ubuntu.com/cookbook/#stop-on

  • 1
    That did the trick. Many thanks! I had assumed that "stop on stopping B" meant "when B stops, A should also stop".. It also seems to mean "before A stops, B should stop", at least in the case I'm testing - ACPI shutdown.
    – Aaron
    Feb 18, 2014 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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