How to depend on an upstart job from an init script on Ubuntu 12.04

I am using Ubuntu 12.04 LTS and this system uses primarily upstart jobs. Unfortunately my system also depends on a manually compiled dbmail server, which only has a init script, but no upstart script.

Using update-rc.d dbmail defaults I installed dbmail for all runlevels, but unfortunately it is started before MySQL is up, so the daemon dies again. I also tried moving it to S90 or the like, still MySQL is not available when the script is run.

I attempted to add a dependency to the LSB header of the script, as follows:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          dbmail
# Required-Start:    $local_fs $remote_fs $syslog $network mysql
# Required-Stop:     $local_fs $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start dbmail services
# Description:       Run network services provided by dbmail such as
#                    imap-server, pop3-server, lmtp-server, timsieve-server
### END INIT INFO

Unfortunately the script still seems to be started before MySQL is. I am used to old-fashined init scripts, not to upstart jobs, so I am a little bit confused here. How can I add the dependency or how can I get the mysql job to start before the dbmail init script?

How can I check / see the start order taken for jobs + init scripts during boot? Is there a tool for this?

Launching the script manually from a shell after startup works fine, as MySQL is already running then.


I think if you run /etc/init.d/dbmail start from /etc/rc.local, it will start after all your upstart jobs/other init scripts.

However, I would probably fix this by adding a new upstart job at /etc/init/dbmail.conf. Usually init.d scripts have a lot of code for checking status, etc., which upstart handles for you. It might be as simple as:

start on started mysql
exec /usr/local/bin/dbmail

Or, you can probably use the existing init script like this:

start on started mysql
pre-start script
  /etc/init.d/dbmail start
end script
post-stop script
  /etc/init.d/dbmail stop
end script