tags:

views:

42

answers:

1

I'm working on my dedicated server running CentOS. I found out that one of my applications which starts up via a script in /etc/init.d/ requires MySQL to be running, or else it throws an error, so essentially I currently have to start it by hand.

How can I detect, in a bash script (#!/bin/sh), whether the MySQL service has started yet? Is there some way to poll port 3306 until it is open to accept connections, and only then continue with the script? Or maybe set an order so that the script doesn't run until the mysqld script runs?

+1  A: 

The init scripts allow you to set the order with the numbering scheme.

Example, in /etc/rc.d/rc5.d you might see:
S98first
S99second

S99second runs after S98first due to the naming.

mrjoltcola
Do I change the order just with a `mv S99second S97second`?
Ricket
Yes, its just about the filename. Typically S99second would be a symbolic link to ../init.d/whatever so it doesn't matter what the original filename is in ../init.d, its the name of the link in the runlevel directory (/etc/rc.d/rc*) that matters for the ordering.
mrjoltcola
Okay, it worked! I noted the number of mysqld in rc5.d and rc6.d (startup and reboot). Then I went into my /etc/init.d script and added a comment as documented in the chkconfig manpage http://linuxcommand.org/man_pages/chkconfig8.html - using, as the startup and shutdown priorities, rc5.d's number +1 and rc6.d's number -1 (respectively). Then I did chkconfig --del myprogram and chkconfig --add myprogram, and checked to make sure chkconfig worked correctly. After a reboot, it took an eternity to start but it did work correctly!
Ricket