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 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.

share|improve this question
add comment

2 Answers 2

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:

http://upstart.ubuntu.com/cookbook/#pre-start

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

share|improve this answer
    
+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
add comment
up vote 0 down vote accepted

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".

share|improve this answer
add comment

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.