I have a Windows service on Windows Server 2008 R2 that I set-up using instsrv
on the srvany.exe
executable. The three values in the Parameters
key are set as follows:
AppDirectory C:\selenium-grid
Application C:\ant\bin\ant.bat
AppParameters launch-hub
The service starts fine and two Java processes appear in the Task Manager when it starts (one process is ant and the other is a Java class launched by ant). When I stop the service the status of the service changes to stopped but the two Java processes do not go away.
How do I get the processes to stop when I stop the service?
Unvortunately, SRVANY sucks. There is an alternative which is the "Non-Sucking Service Manager" (NSSM) - it will shut down your application and all child processes on the service stop signal.
Unfortunately, srvany.exe does not provide any method for killing the process(es) when the service is stopped, so basically your options are to (a) look for a third-party alternative which does provide this functionality or (b) write such a replacement yourself.
Perhaps another reader knows about a good third-party alternative, or you might get lucky with a Google search. If you decide to go with option (b) I may be able to give you a head start, so drop me an email if you like - my address is in my profile. Or you could post a question to StackOverflow.
Srvany has a few well known shortcomings, one of which is not terminating the process it starts.
Be sure to read about other potential issues on this page comparing Srvany to AlwaysUp (our commercial application which will close all sub-processes as you expect) to reduce the surprises...