Bug #45546 Bug&Feature request: start windows service, then execute what is needed.
Submitted: 17 Jun 7:19 Modified: 17 Jun 21:43
Reporter: Roel Van de Paar
Status: Verified
Category:Server: Windows Severity:S2 (Serious)
Version: OS:Microsoft Windows
Assigned to: Target Version:
Triage: Triaged: D5 (Feature request)

[17 Jun 7:19] Roel Van de Paar
Description:
o Windows only waits about 30 seconds for a service to start.
o InnoDB startup may take more.

POC:
-------
C:\mysql5.1.35>net start mysql5135
The mysql5135 service is starting....................
The mysql5135 service could not be started.

More help is available by typing NET HELPMSG 3523.

C:\mysql5.1.35>net helpmsg 3523

The *** service could not be started.
-------

How to repeat:
o Clean mysql with no ib* files
o Use innodb_data_file_path=ibdata1:6G;ibdata2:6G:autoextend in my.ini
o Start service

Unless you have a fast machine, this will show the issue.

Suggested fix:
Start the service first, then execute what is needed.

Or, possibly better, use SetServiceStatus
(http://msdn.microsoft.com/en-us/library/ms686241.aspx) regularly to tell Windows that
the service is still starting normally:

'During initialization, the service can provide updated status to indicate that it is
making progress but it needs more time.'

Also see the URL above for gotchas ('A common bug is for the service to have the main
thread perform the initialization while a separate thread continues to call
SetServiceStatus to prevent the service control manager from marking it as hung. However,
if the main thread hangs, then the service start ends up in an infinite loop because the
worker thread continues to report that the main thread is making progress.')
[17 Jun 7:48] Sveta Smirnova
Potentially can lead to same problem as in bug #41908
[17 Jun 21:43] Valeriy Kravchuk
Windows should not let to start service that is already started/is in the process of
starting.

I think this is a reasonable feature request.
[12 Oct 4:02] Roel Van de Paar
If the server is slow in shutting down, possibly the same issue may happen during
shutdown. 

Workaround: use:

shell> SC INTERROGATE <service_name> | FIND "STATE" 

To check if the service has successfully started/stopped. Example:

---------
C:\>NET START mysql5137
The mysql5137 service is starting.
The mysql5137 service was started successfully.

C:\>SC INTERROGATE mysql5137 | FIND "STATE"
        STATE              : 4  RUNNING

C:\>NET STOP mysql5137
The mysql5137 service is stopping.
The mysql5137 service was stopped successfully.

C:\>SC INTERROGATE mysql5137 | FIND "STATE"

C:\>
---------