I have an Upstart job configured using the task stanza, which another job depends on being finished before it starts. However, this job must also wait for a different service to be started before it starts. This causes some problems - the job will start if the task finishes before the dependent job has started, but it will not start if the task finishes after the job starts.

For example, let task-a be the task that the job depends on, then this is the job's configuration file:

start on (stopped task-a and started cups)

    echo do stuff
end script

How can I get a job like the one above to start once the task has finished but after another job has started? I can modify the task if necessary, but I don't think sleeping forever is a very good solution. The Ubuntu version in this case is 12.04.


I'd have the first job "emit" its own signal (this is a command):

initctl emit job-a-done

And jump on that in my upstart job...

start on started cups and job-a-done

This is outlined in the cookbook.

  • Unfortunately this hasn't worked. The first job emits a signal, but the second one still doesn't start. I suspect this is because in some cases CUPS hasn't 'started' by the time the signal gets emitted. – Xenopathic Oct 16 '13 at 13:46

OK, so after a lot of trouble trying to get this to work, I have given up. I've tried:

  1. Getting the job to start after one job is started and another one has stopped (a task)

    start on (started cups and stopped my-task)
  2. Getting the job to start after one job is started and the other one has emitted a signal (see Oli's answer)

    start on (started cups and my-task-finished)
  3. Getting the job to start after both jobs have started (the task job waits infinitely)

    start on (started cups and started my-task)

None of the above attempts worked. For reference, I wanted to have the job start once CUPS is started and my task has finished. When CUPS had printers configured, it would start slowly and the script would run correctly (in cases 1 and 3, 2 never worked properly). However, when CUPS did not have any printers configured it would start instantly (I mean, WTF Upstart, why does this happen in the first place?) but more importantly my job would not run.

I have come to the conclusion that Upstart in Ubuntu 12.04 LTS is completely broken. I'm not sure if this is a bug that is fixed in a newer version of Ubuntu, but this is a pretty major problem.

So, the solution. Don't use Upstart. Switch to systemd if possible or use SysV in the cases where it is not available/not viable to maintain. Oh, and Canonical, please fix this.

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.