Page 1 of 1
Stop service continuing too early
Posted: Mon Jun 18, 2012 8:30 am
by tosch
I have used the Control Service command stop a service before I apply a new version. I have also ticked the 'wait for service...' checkbox.
It seems that the wait finishes too early. I'm installing new files and I always have to reboot for the files to be replace. When I check the service just before installing the new files it's in 'stopping' mode. The service takes a little while to shut down because it does some cleanup/shut down stuff.
Is there a way to wait until the service is in mode 'stopped'?
Thomas
Re: Stop service continuing too early
Posted: Mon Jun 18, 2012 10:23 am
by FrancescoT
Dear Thomas,
Sometimes could happens that services takes more time to effectively stop and the reason can be related to different factors.
Honestly, I faced the same problem with a service and I could suggest you some ways to handle the issue.
-1 You could create a loop (or an if statement) that checks if the service has really stopped using the returned variable from "Check Service" command.
If you use a loop pay attention to repeat the loop only for a maximum number of times ... otherwise your process could be blocked if somethings goes wrong.
-2 You could call sleep WIN API function after Control Service. This will suspends the execution of the setup thread until the time-out interval elapses.
The function is available with Kernel32.dll and you can refer to MSDN documentation for more information.
-3 You could try to use the plugin available with following link that uses a different approach to control a Service.
http://www.installaware.com/forum/viewt ... f=3&t=6859
Hope this helps you.
Regards
Re: Stop service continuing too early
Posted: Tue Jun 19, 2012 3:24 am
by bokkie
I'm not on my PC at this moment but isn't there a DOS command that lets you stop and start services? I recall something but not the name. But something in my mind hints at "net stop" or something like that? If you identify the exact command you could then run it with parameters in the MSIcode. I think many of us might agree that running a DOS command using MSIcode is very predictable. That might help you to approach the issue from a different angle?
To be sure, I've controlled services in my installers before and I've never had a problem stopping the installation until the service action requested has terminated. That also included a period of cleanup as well before returning. If you click the stop button against the service in Windows' Service Management Console how long does it take for the service to switch from running to stopped? This might reveal a longer than expected period of time but it really shouldn't make a difference whether it takes a second or ten minutes to stop the service.
Edit: I'd have expected the startup of a service to be more error-prone as Windows requires the OnStart event to complete in at most one minute before the service enters a failed state. Also, are there any messages written in your event viewer which might list a problem? Again, I know from experience that Windows gets very chatty when services fail to start or stop so the event viewer might contain a trace of some problem?
Re: Stop service continuing too early
Posted: Tue Jun 19, 2012 8:36 am
by FrancescoT
Dear Bokkie,
You are right. A service can also be stopped, started, resumed and so on using the net command from Command Prompt also.
This can be done using the following sintax;
net start service
net stop service
net pause service
net continue service
I am not quite sure if the above commands returns a value ... but probably yes.
I have developed several SERVICES applications and sometimes can happens that a service requires time to be really stopped.
Generally and as described in WIN API documentations, a service must be stopped within a maximum time limit (... that actually I do not remember).
The time required for a service to stop is related to many factors, the current state of the service at the moment that it receives the request to stop, services dependencies and resources used by the service itself.
Sometimes could happens that a request to stop returns before that the service it is really stopped. This very often doesn't means that the service is unable to stop because in reality is still stopping. In fact it is very common to have the service stopped just few milliseconds after.
Regards
Re: Stop service continuing too early
Posted: Tue Jun 19, 2012 9:16 am
by bokkie
Francesco, I also recall a situation when I stopped a service and it failed to stop successfully and it displayed a fatal error message. To be honest, it wasn't our service and we couldn't understand why it failed to stop. Eventually, we realised other services were dependent on the one we wanted to stop. It was the other services that were causing the one we wanted to stop to flag an error.
Re: Stop service continuing too early
Posted: Tue Jun 19, 2012 9:46 am
by FrancescoT
Dear Bokkie,
your are right ... this could happens also.
Regards