3

for some reason i need to start apache2 only after mysql is running on one of the servers.

i've tried:

  • renaming scripts in /etc/rc2.d to give S0Xmysql lower number than S0Yapache2 - but it did not help.
  • editing /etc/init.d/apache2 and adding Required-Start $mysql

but still when i watch the screen at the bootup i see

INIT: Entering runlevel: 2
...
Starting web server: apache2Action 'start' failed.

and only then

Starting MySQL database server: mysqld

thx

pQd
  • 29,981
  • 6
  • 66
  • 109

1 Answers1

9

At the top of /etc/init.d/apache2, you'll see the lsb-header section which looks like this:

### BEGIN INIT INFO
# Provides:          apache2
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop apache2 web server
### END INIT INFO

You want to copy this text into a new file you'll create named /etc/insserv/overrides/apache2. Change the Required-Start line by adding "mysql" to the end of the line. then run insserv -d. You should then see that the startup link for apache2 is moved to be later than mysql.

stew
  • 9,388
  • 1
  • 30
  • 43
  • thanks, it looks neatly but unfortunately did not help. apache2 still starts before mysql. i tried adding both mysql or $mysql at the end. can you suggest how can i enable logging of the startup process so i can see what's exactly going on? thans! – pQd Dec 13 '11 at 15:02
  • @pQd I edited my answer because originally I had forgotten the `END INIT INFO` line. does insserv give any errors when you run it? does `insserv -d -vv 2>&1 | grep apache` mention that it is loading your newly created file from /etc/insserv/overrides? – stew Dec 13 '11 at 15:09
  • i actually included the END INIT.. insserv -d -vv seems to load the data from newly created config: http://pastebin.com/P185Wrfm – pQd Dec 13 '11 at 15:16
  • hmm, odd. Can you pastebin the LSB headers from both your apache2 override and the msyql init script just to check? I've tried this locally and it works for me. I guess a listing of /etc/rc2.d (or whichever runlevel you are working on) would be helpful too. – stew Dec 13 '11 at 15:28
  • sorry... i'm a moron. your suggestion did work. thank you very much! can you suggest something i can read to feel more comfortable with the new LSBInitScripts [besides first few links from google that i'll take a look at]? – pQd Dec 13 '11 at 15:55
  • :) did you see the link in the first line of my response? – stew Dec 13 '11 at 16:01
  • yes... i saw it. anyway i'll google more for some practical examples. thx – pQd Dec 13 '11 at 16:02
  • Thank you - this works perfectly and saved me from many (more) hours of digging and head-scratching. – rainecc Feb 13 '13 at 19:59