Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the problem that my apache2 doesn't start at boot. After debugging I found out that a webpage init script tried to connect to MySQL which isn't running at that time.

My OS is Ubuntu Server 10.04.4

apache2 boot is set up using update-rc.d apache2 defaults 21 which creates the scripts in /etc/rcX:

root@ser:~# find /etc/rc* -name *apache*

and calls /etc/init.d/apache2

mysql is getting started by Ubuntu's upstart:

root@ser:~# ls /etc/init | grep mysql

How can I force apache2 to start AFTER mysql?


Since I got already a few comments, here a clarification:

Apache is started as a sysvinit script under /etc/rc*.d/ whereas mysql is an upstart script under /etc/init/. Mysql isn't listed under /etc/rc*.d and thus I can't change the priority by changing the alphabetical order!

share|improve this question
The answer to your question is YES. – mdpc Jun 5 '13 at 19:16
Please do your research, this type of question has no doubt been asked and answered a number of times either here or in SuperUser or Unix SEs. – mdpc Jun 5 '13 at 19:18
I did my research, but it seems my question wasnt clear enough. The only thing I found was on how to change the priority when both scripts are under /etc/rc*.d/. But the problem here is that one is a sysvinit script, the other an upstart script. – SailAvid Jun 5 '13 at 19:27
Can you give more details about the 'webpage init script tried to connect to MySQL'. I would guess that apache would start, and one web site can't connect to mysql, but will work fine after mysql gets started. Is this the problem you are seeing? – becomingwisest Jun 5 '13 at 20:24
I found this, might be helpful [askubuntu][1] [1]:… – APZ Jun 5 '13 at 20:38
up vote 2 down vote accepted

To answer my own question:

Here is a quick and dirty way to block the apache script until mysqld is started:

Replace the two lines in /etc/init.d/apache2

 log_daemon_msg "Starting web server" "apache2"
 if $APACHE2CTL start; then


log_daemon_msg "Starting web server" "apache2"

# wait until mysql started
while [ "$WHILE_CNT" -le 60 ] ; do
        if [[ `service mysql status` == *running* ]]; then
        WHILE_CNT=`expr $WHILE_CNT + 1`;
   sleep 1

if $APACHE2CTL start; then

This checks every one second if mysql is running (maximum check time is 60 seconds).

But there should be a better way to defince dependencies between sysvinit and upstart services?!

share|improve this answer
I don't really agree with this approach of looping INSIDE a startup script. How are you assured that mysql will be coming up at all and in which order it is being called. – mdpc Jun 5 '13 at 19:49
You are right! This script blocks for at maximum 60 seconds the whole bootup proces. Thus I wrote 'quick and dirty'. There isn't any assurance that mysql will come up. As far as I understood, Upstart and Sysvinit are executed in parallel. Thus mysql should come up during the time apache waits. If it doesn't, than apache wouldn't start neither (which makes sense because the webpage needs mysql). I think there should be a better way to do this which avoids these problems! – SailAvid Jun 5 '13 at 20:29

Your Answer


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.