Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 492
João Avatar asked Aug 12 '11 23:08

João


2 Answers

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").
like image 78
João Avatar answered Nov 15 '22 03:11

João


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. enter image description here

Get the PID of your target service using: sc queryex ServiceName:

Kill the process using taskkill /f /pid your_PID_number

like image 30
AlexandruC Avatar answered Nov 15 '22 03:11

AlexandruC