Bug #30607 Tomcat sometimes starts before MySQL is fully started and ready for connections
Submitted: 23 Aug 2007 23:08 Modified: 27 Aug 2007 18:41
Reporter: Andy Bang Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Enterprise Monitor: Installing Severity:S2 (Serious)
Version:1.2.0 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: mer 121

[23 Aug 2007 23:08] Andy Bang
Description:
The basic logic in mysqlnetwork.bat and mysqlnetwork.sh is:

    start mysqld
    wait 5 seconds
    start tomcat

While this mostly seems to work, we've seen cases where tomcat is started before mysqld is full started and ready for connections.  This creates major problems for our app and we would prefer to handle this dependency in the startup scripts.

How to repeat:
See Description.

Suggested fix:
1) On Windows, specify the dependencies in the registry so that when Windows is rebooted it knows about them.  See http://support.microsoft.com/kb/q193888/ for more info.

2) Because we install shortcuts to start and stop these services on the Start menu in Windows, we also need fix the problem in the startup script.  Please incorporate something like the following into mysqlnetwork.bat instead of just relying on "ping localhost -n 5  > NUL":

:waitForMySQL
@echo Waiting for MySQL to start
ping localhost -n 5  > NUL
mysqladmin ping -ufakeuser 2> NUL
if %errorlevel% NEQ 0 goto waitForMySQL
@echo MySQL Is Running!

3) Please incorporate something like the following into mysqlnetwork.sh instead of just relying "sleep 5":

mysqlWaitFlag=1
while [ "${mysqlWaitFlag}" != "0" ]
do
    echo "Waiting for MySQL to start"
    sleep 5 > /dev/null
    mysqladmin ping -ufakeuser 2> /dev/null
    if [ "${?}" = "0" ]; then
        mysqlWaitFlag=0
    fi
done
echo "MySQL is running!"

Note that you do not need a valid login to MySQL for this to work -- you can just use "-u fakeuser".
[24 Aug 2007 9:47] Carsten Segieth
A similar problem sometimes seen on Linux when stopping the server. Here the mysqlnetworkctl.sh script returns control to the calling process and 'later' the message from the stopping mysql appears. This 1) can cause problems as the calling process cannot be sure that both processes are really stopped when control is back and 2) it does not look nice, e.g. when during uninstalling the server the mysqld stop message appears when already the progress bar is displayed.
[24 Aug 2007 9:56] Carsten Segieth
[qauser@net-qa1 18080]$ ./mysqlnetworkctl.sh stop
Using CATALINA_BASE:   /home/qauser/merlin/monitoring/1.2.0.7214/net-qa1/18080/apache-tomcat
Using CATALINA_HOME:   /home/qauser/merlin/monitoring/1.2.0.7214/net-qa1/18080/apache-tomcat
Using CATALINA_TMPDIR: /home/qauser/merlin/monitoring/1.2.0.7214/net-qa1/18080/apache-tomcat/temp
Using JRE_HOME:       /home/qauser/merlin/monitoring/1.2.0.7214/net-qa1/18080/java
./mysqlnetworkctl.sh : mysql stopped
[qauser@net-qa1 18080]$
[qauser@net-qa1 18080]$ STOPPING server from pid file /home/qauser/merlin/monitoring/1.2.0.7214/net-qa1/18080/mysql/data/mysqld.pid
070824 11:55:26  mysqld ended
[6 Nov 2009 7:21] Enterprise Tools JIRA Robot
Carsten Segieth writes: 
yes, this is - at least on Windows - still an issue. 

On Linux/Unix the logic is to wait up to 120 sec for a started mysqld, and this seem to be 'enough' in almost all cases.

On Windows the basic logic is still to wait for '5 pings' between the starts and there is no dependency set between the 2 services. So happens often to me during the installation process that the Tomcat service is started although the just started MySQL process is blocked by a question from the firewall. A dependency could help here. Also later in the "daily work" this dependency would make sure that Tomcat is started only if MySQLd is up.
For uninstall I needed to remove the dependency as first action to make sure that no user confirmation is requested during stop / remove of the services.
[13 Mar 2014 13:36] Omer Barnir
This bug is not scheduled to be fixed at this time.