On Ubuntu 10.04, I need to start my service with upstart, but only when mysql is up and running.

The problem is that mysql itself is not handled by upstart, so I can't use the "start on" feature.

What can I do ?

3 Answers 3


You have a few options:

1) make mysql inform Upstart that it has started by emitting an event

initctl emit mysql-started" or similar.

This could be handled by adding the initctl invocation to /etc/init.d/mysql.

2) Disable mysql from the normal SysV runlevels and create a wrapper Upstart job that starts it (not this doesn't handle stopping - just an example):

cat >>/etc/init/mysql-sysv.conf<<EOT
  # wait for SysV job to finish
  start on stopped rc
  exec /etc/init.d/mysql start

Then, have your job "start on started mysql-sysv".

The problem here is that you'll run into trouble if someone (or some system tool automatically) re-adds the /etc/rc?.d links to the original /etc/init.d/mysql service script. Also, you may find that mysql isn't actually ready until some time after it's main pid has started. Databases are problematic as they might take some time to come "online" even after they have started (transction log replay, etc).

3) Create an upstart job ("waiter") that does "start on stopped rc" (ie start when all the SysV jobs have claimed to have finished) and then polls waiting for mysql to become ready, then exits. Have your job "start on stopped waiter".

4) Convert mysql to an Upstart job (the best option). There's a starting point for an upstart mysql configuration up here: https://github.com/devo-ps/init-scripts/tree/master/mysql/ubuntu

  • 1
    After looking around, this answer sums up all the options I have. Also thank you for pointing out the gap between "started mysql" and the time when mysql is actually available. Let's see if #4 was already tried somewhere.
    – Falken
    Mar 28, 2012 at 20:20
  • Option 3 requires "start on started waiter". Not on stopped.
    – adeandrade
    Jul 18, 2014 at 22:27
  • option 1 fits our model well! We first download all upstart scripts from a config server via python script which runs os.system('/sbin/initctl emit consul-finished'), then start other services by start on consul-finished
    – CMag
    Jan 18, 2016 at 1:33
  • Thanks for that, my friend! Basically I ended up having to sed-replace initctl emit cloud-init-finished a sysv service to be able to hook up
    – Jose Alban
    Feb 8, 2017 at 15:31

I suggest starting your upstart job after all non-upstart jobs are finished:

start on started rc

/etc/init/rc.conf is the thing that starts non-upstart jobs from within upstart.

Props: https://serverfault.com/a/533481


How about using

pre-start exec /etc/init.d/mysql start

inside your upstart job !

  • ...that will not magically start the upstart job when mysql starts.
    – adaptr
    Mar 16, 2012 at 12:02
  • yeah that is not what you asked!!! you asked for other way round . At least that is how i understood
    – kaji
    Mar 16, 2012 at 12:19
  • My upstart job is supposed to monitor mysql and send notifications if it's down. I feel a bit unconfortable launching mysql via the monitoring job
    – Falken
    Mar 16, 2012 at 13:18
  • I don't think is entirely wrong. I do something like this: pre-start script if ! /etc/init.d/rabbitmq-server status &>/dev/null; then /etc/init.d/rabbitmq-server start fi end script
    – maxadamo
    May 11, 2016 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.