Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is stopping (not crashing) my windows service?

We have a .NET Windows Service that occasionally shuts down on one particular server, about three times in the last month. Logging shows that the OnStop method is being called, so I don't think the service is crashing. However, we don't know what's shutting down the service.

Is there any way to find out what's shutting down the service? Is there anything I can log during OnStop? The Windows Event Viewer just shows application shut down and the security log does not show any user account authenticated at the time.

The service is running in .NET 3.5 SP1 on Windows Server 2003 SP2 (5.2.3790).

There are no service dependencies. This service doesn't depend on any other services and no other services depend on this service.

like image 660
Samuel Neff Avatar asked Jul 27 '11 02:07

Samuel Neff


People also ask

What to do when a service is stuck in stopping?

The easiest way to stop a stuck service is to use the built-in taskkill command-line tool. First of all, you need to find the PID (process identifier) of the service. As an example, let's take the Windows Update service. Its system name is wuauserv (you can check the name in the service properties in the services.

What does stopping a Windows service do?

When a service is paused, it can maintain internal state, including cached information or possibly even a queue of waiting work items. The service can then be resumed to pick up where it left off. If the service is stopped, internal state is discarded. Starting the service again should repeat all initialization.

How do I know who stopped a service in event viewer?

Save this answer. Show activity on this post. In Event Viewer, look in the "Windows Logs"->"System" event log, and filter for Source "Service Control Manager" and Event ID 7040. Find the event saying "The start type of the service was changed from original start type to disabled" for the service you're interested in.


1 Answers

There is no way to tell from within the service since this called from the SCM - whoever asked SCM to stop your service isn't visible to the service...

I think your main option is checking the EventLog around that time... are other services being shutdown too ? is any scheduled taks running etc. ?

A "rather dirty" option (last resort/desperate) would be to set CanStop to false... in this case there will be someone seeing a problem in stopping your service and "hopefully" ask you why your service is not stoppable...

like image 113
Yahia Avatar answered Oct 02 '22 03:10

Yahia