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 ?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
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
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 EOT
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
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.
How about using
pre-start exec /etc/init.d/mysql start
inside your upstart job !