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 do status A | grep -q "stop/waiting" && exit 0 sleep 1 done 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?