Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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
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

share|improve this answer
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 '12 at 20:20
    
Option 3 requires "start on started waiter". Not on stopped. –  adeandrade Jul 18 at 22:27

How about using

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

inside your upstart job !

share|improve this answer
    
...that will not magically start the upstart job when mysql starts. –  adaptr Mar 16 '12 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 '12 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 '12 at 13:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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