Force apache start after mysql
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*
/etc/rc0.d/K21apache2
/etc/rc1.d/K21apache2
/etc/rc2.d/S21apache2
/etc/rc3.d/S21apache2
/etc/rc4.d/S21apache2
/etc/rc5.d/S21apache2
/etc/rc6.d/K21apache2
and calls /etc/init.d/apache2
mysql is getting started by Ubuntu's upstart:
root@ser:~# ls /etc/init | grep mysql
mysql.conf
How can I force apache2 to start AFTER mysql?
Update:
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!
Solution 1:
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
with
log_daemon_msg "Starting web server" "apache2"
# wait until mysql started
MYSQL_OK=0
WHILE_CNT=0
while [ "$WHILE_CNT" -le 60 ] ; do
if [[ `service mysql status` == *running* ]]; then
MYSQL_OK=1;
break;
fi
WHILE_CNT=`expr $WHILE_CNT + 1`;
sleep 1
done
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?!