I am working on a package that needs two Upstart jobs: one that launches a daemon, and another that launches a supporting daemon if the configuration file requires it. The logic to determine if the supporting daemon should be launched involves processing the configuration file with sed and friends, which causes problems with Upstart's daemonization detection (Upstart has no way to distinguish PIDs), so expect fork and expect daemon aren't useful. Unfortunately, this means Upstart detects the first invocation of sed as the first PID, and immediately starts the main job, before the supporting daemon is fully initialized. This frequently leads to the premature termination of the main job, due to an improperly configured environment.

Is there any way to prevent Upstart from starting the main job too soon in this scenario?

expect stop looks like it's close to what I need, but I don't see a way to raise that signal without terminating one of the daemons, neither of which generate the SIGSTOP signal on their own.


Simple - use a pre-start stanza to perform all your sed checking. If the pre-start determines that the supporting daemon should not be started, have it call simply stop (which forces Upstart to not continue starting the job). There is an example of this in the Upstart Cookbook here:


Note that Upstart only performs PID tracking for the exec and script stanzas (in other words the "main" part of the job) - PIDs for pre-start, post-stop et al are not tracked. See http://upstart.ubuntu.com/cookbook/#expect

  • +1 for pointing out stop (I wasn't aware of that command), but I was wanting to delay the start, not prevent it entirely. – cqcallaw Jul 18 '12 at 2:54

The solution to this ended up being in the Upstart documentation:

Create a post-start section that performs some check and only returns once the service is "ready".

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.