I have three Ubuntu Upstart scripts:

  • browser runs an instance of firefox as an unprivileged user
  • browsers starts when screen is started and launches
    • browser PORT=1
    • browser PORT=2
    • browser PORT=3
  • screen starts a Xvfb server

The chain is:

  1. screen starts at runlevels 2, 3, 4, 5
  2. browsers is configured to start on started screen and to stop on stopping screen
  3. each instance browser PORT=? will stop on stopping browsers and will be started by browsers


screen starts fine but doesn't start browsers (or it does and browsers fails to start browser PORT=?).

If I sudo start browser PORT=1 everything works fine, whereas sudo start browsers doesn't even start itself.


env DISPLAY=:99
env USER=worker

start on runlevel [2345]
stop on runlevel [!2345]


        su ${USER} -c "/usr/bin/Xvfb ${DISPLAY}"
end script

start on started screen
stop on runlevel [!2345] or stopping screen


expect fork #the following "start browser ..." do fork

       start browser PORT=4242
       start browser PORT=4243
       start browser PORT=4244
       start browser PORT=4245
end script

instance $PORT

stop on runlevel [!2345]
stop on stopping browsers or stopping screen


        su ${USER} -c "/usr/bin/firefox -no-remote -P ${PORT} --display ${DISPLAY}"
end script

UPDATE (10/21/2010): the (modified) code above now works. However, when I need to stop browsers, all the instances of browser PORT=? are correctly terminated, while ``browsers` gets stuck.

How do I solve this other issue?

  • It's important to know what version of upstart you use. – JanC Oct 19 '10 at 19:45
  • @JanC: 0.6.5-7 on Lucid Lynx Server. – phretor Oct 20 '10 at 9:08

Lucid comes with upstart v0.6.x, which means you can't have multiple "stop on" or "start on" lines. You have to combine the conditions together with and, or & parentheses.

You can read the job description syntax in the init(5) manpage (available online or run man 5 init in a terminal).

  • using the right syntax solved my problems, i.e., now they boot. Unfortunately, to make browsers booting I had to put "expect fork" (because "start browser PORT=4242" forks). This causes "sudo stop browsers" to stuck). Any suggestion? – phretor Oct 21 '10 at 16:49
  • Maybe it forks too often so that upstart doesn't know the correct PID (that's a known problem with the current upstart, and which should be fixed in the next release of it) – JanC Oct 23 '10 at 2:59

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.