Share via


Service Control Manager Doesn't Restart Service On Failure

Question

Thursday, December 13, 2018 2:23 PM

Hello,

I have developed a service and set it's recovery options as;

  • First Failure: Restart the Service
  • Second Failure: Restart the Service
  • Subsequent failures: Restart the Service
  • Reset fail count after: 1 days
  • Restart service after: 0 minutes
  • Enable actions for stops with errors: checked

And Opened Task Manager.

If I kill service process using Details Tab and right click to process and select End Task then My Service restarts immediately.

But if i go to Processes Tab and background processes section and find my process then right click it and select End Task, then my service doesnt restart. 

Is this a bug or i am missing something.

All replies (11)

Thursday, December 13, 2018 2:39 PM | 1 vote

Check your system event log  for Service Control Manager entries. I followed the steps you described and it is working as expected. Maybe your service can intercept the end task event and do a controlled shutdown. 

Log Name:      System
Source:        Service Control Manager
Date:          12/13/2018 9:31:38 AM
Event ID:      7031
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      test10
Description:
The Adobe Acrobat Update Service service terminated unexpectedly.  It has done this 1 time(s).  The following corrective action will be taken in 60000 milliseconds: Restart the service.


Thursday, December 13, 2018 2:57 PM

I have checked my event log end it has event log like this, but service doesn't start.

Killing Service Process Using Task Manager Details Section;

Log Name:      System
Source:        Service Control Manager
Date:          12/13/2018 17:55:22
Event ID:      7031
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      win10
Description:
The MyTest service terminated unexpectedly.  It has done this 9 time(s).  The following corrective action will be taken in 0 milliseconds: Restart the service.

Killing Service Process Using Background Processes Section;

- No Log In Event Log -


Thursday, December 13, 2018 3:20 PM | 1 vote

Is the process really going away? Download and run Process Explorer from sysinternals.com (Microsoft). Find your service and note the process names and PID numbers. Use CTRL+T to show the process tree. Under the View menu set the update speed to 10 seconds. Then kill the service in the background processes section. Recheck procexp to verify that all processes terminated. 

Does your service have its own logging function? Anything interesting in those logs?

 


Thursday, December 13, 2018 3:55 PM

Yes process is really going away because when i check from services.msc, service seems stopped.

My service has own logging function and there is nothing interesting. 

I have opened Process Explorer and find my service process then killed with Process Explorer. My service restarted immediately. 

But when i do this operation using Windows task manager's background processes section, my service doesn't restart and there is no eventlog in system.

I will do more research about it, maybe 0 minutes is not a good choice for service recovery. I will try something bigger than 0. 


Thursday, December 13, 2018 4:32 PM | 1 vote

But when i do this operation using Windows task manager's background processes section, my service doesn't restart and there is no eventlog in system. 

Did the processes terminate when you did it that way? Does your service log a startup event? 

I will do more research about it, maybe 0 minutes is not a good choice for service recovery. I will try something bigger than 0. 

I normally have it reset after 1 day and restart after at least 1 minute to give all process time to clean up.


Friday, December 14, 2018 2:01 AM | 1 vote

@harun kocacaliskan,

>>I will do more research about it, maybe 0 minutes is not a good choice for service recovery. I will try something bigger than 0.

Yes, you get the point.

Look at this similar case:

Windows Services Recovery option doesn't work ... or I don't understand it

https://social.technet.microsoft.com/Forums/en-US/e2919c56-60a8-4dc2-b508-7491522ab269/windows-services-recovery-option-doesnt-work-or-i-dont-understand-it?forum=ws2016

to fix this, set the failure count to reset after one day.  The drawback to this approach is your service may stay stopped after failing several times but this likely means something is toast anyways.

What’s more, Service Recovery only works for unexpected exit like (exit(-1)) call. For all the way we use to stop the service in usual way will not works for recovery. If you want to stop service and still wants recovery to work, call exit(-1) and you will see error message as "service stopped with unexpected error" , and then your service will restart as recovery setting is.

Regards

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Friday, December 14, 2018 6:55 AM

I have read that thread but in my opinion my problem is different.

https://docs.microsoft.com/tr-tr/windows/desktop/api/winsvc/ns-winsvc-\_service_failure_actionsa

"The service control manager counts the number of times each service has failed since the system booted. The count is reset to 0 if the service has not failed for dwResetPeriod seconds. When the service fails for the Nth time, the service controller performs the action specified in element [N-1] of the lpsaActions array. If N is greater than cActions, the service controller repeats the last action in the array."

Now The question is how a service fails? Or how service control manager decides a service has failed?

https://docs.microsoft.com/tr-tr/windows/desktop/api/winsvc/ns-winsvc-\_service_failure_actions_flag

FailureActionsOnNonCrashFailures

"If this member is TRUE and the service has configured failure actions, the failure actions are queued if the service process terminates without reporting a status of SERVICE_STOPPED or if it enters the SERVICE_STOPPED state but thedwWin32ExitCode member of the SERVICE_STATUS structure is not ERROR_SUCCESS (0).

If this member is FALSE and the service has configured failure actions, the failure actions are queued only if the service terminates without reporting a status of SERVICE_STOPPED."

As I understand if my service process is killed without stopping service, Service Control Manager will recover it if i set an action.

Everything seems good until this point;

If I Kill My Service Process with Process Explorer, or CMD taskkill command, Or Task Manager's Details Tab everything is working as it should be.

But if I Kill My Service Process with Windows Task Manager's Background Processes Section;

My Service doesnt restart;

I dont have any event log in system;

My question is; What is the difference between these?

Why my service doesn't restart if i kill it with task manager, and why it restarts if i kill with process explorer?

I tried it with Print Spooler Service too. I killed Print Spooler Service via background processes section, service didnt restart. Nothing in event log.

I killed Print Spooler Service via Process Explorer, it restarted via Service Control Manager and I have a system log in event log.

Can you try it? My os is Windows 10 Pro - Version 1809

UPDATE:

I have tried same scenario in Windows 10 Home, everything working well. Compared "taskmgr.exe" with mine, they are different version. Copied taskmgr.exe from Windows 10 Home, but couldnt get it work in Windows 10 Pro, maybe signature problem. 


Friday, December 14, 2018 1:52 PM | 1 vote

I too have Win10 Home.  Looks ok here.

  Log Name:      System
  Source:        Service Control Manager
  Date:          12/14/2018 8:36:36 AM
  Event ID:      7031
  Task Category: None
  Level:         Error
  Keywords:      Classic
  User:          N/A
  Computer:      slick
  Description:
  The Print Spooler service terminated unexpectedly.  It has done this 1 time(s).  The following corrective action will be taken in 5000 milliseconds: Restart the service.

If you don't see any event in the system event log, then the service is not changing status. There should be an event for every service start, service stop, and service crash.

Have you verified with Process Explorer that your process does in fact terminate when you end it with Background Processes?


Monday, December 17, 2018 12:05 PM

Yes, it terminates and service stops.


Monday, December 17, 2018 2:36 PM | 1 vote

I built a Win 10 Pro VM and upgraded it to 1809. I tested as you suggested and it worked fine. I see event 7031 in the system event log. If your service stops, then there should be an event in the system eventlog. If you don't have one then something is very wrong with the pc.  Is this the only machine that is having the problem? Can you check other 1809 machines? Test with the Print Spooler service.  

In lieu of any concrete evidence of a problem, then run the standard "I've got a problem" commands.

Dism /Online /Cleanup-Image /CheckHealth
Dism /Online /Cleanup-Image /ScanHealth
Dism /online /cleanup-image /analyzecomponentstore
Dism /Online /Cleanup-Image /restoreHealth
sfc /scannow


Tuesday, December 18, 2018 11:30 AM

Hi, thank you for useful info.

I have tested it on VirtualBox VM, and downloaded image from microsoft download site. 

I have used this ISO when installing. 

Win10_1809Oct_Turkish_x64.iso

Can you post your TaskManager version info please. And Do you kill print spooler service from background processes tab, or details tab?