Stop/Start Service - Handling STOP_PENDING and START_PENDING
How do you make your stop/start service 开发者_开发技巧scripts gracefully handling the services that get stuck in STOP_PENDING or START_PENDING...
Related with SC STOP and START. Stop and Start a service via batch or cmd file?
I have one aproach in mind, but I don't like it.
This is the way i'm approaching the stop.
- Stop: sc %host% stop %service% || ECHO ERROR! && EXIT -1
- Loop waiting for state to be STOPPED. Loop with a maximum number of iterations (e.g. 30). Testing if service is stopped (e.g. sc %host% query %service% | find /i "STOPPED"). Wait some seconds in each iteration (e.g. 10). Reaching the maximum iterations, try to kill the process using taskkill (e.g. work the output of sc queryex Alerter | find /i "PID").
First open service.msc, in the properties dialog for your targeted service go to the Recovery Tab *(run -> services.msc -> right-click Target-Service -> Properties -> Recovery tab*)
Make sure the First\Second\Subsequent failures are all set to : Take No Action.
Get the PID of your target service using: sc queryex ServiceName:
Kill the process using taskkill /f /pid your_PID_number
For me sometimes a 'Windows service' is hanging when I have the window services.msc
open. I can't kill the process, neither use net stop
or sc stop
.
But when I close the services.msc
window, the service immediately stops.
精彩评论