15

When trying to restart an existing windows service via NSSM, I randomly get the below message which is written to the error log/error output. Any ideas on how to rectify? Ideally, accept as a valid response.

Unexpected status SERVICE_START_PENDING in response to START control

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
johnnyboy
  • 869
  • 12
  • 23
  • This depends on how the service is written. A badly written service can "easily" exhibit that kind of behavior. I don't think you can get any help without any more information. – Simon Mourier Dec 19 '18 at 21:40
  • Can you provide some extra information about your problem? – Kousic Dec 20 '18 at 04:55
  • Running `nssm restart ` will try to send a stop control followed by a start control. It will fail if the service was stopped at the outset or if it didn't respond to the stop control in a timely manner. Wait for the service status to change, eg from START_PENDING to RUNNING before deciding whether a service control operation was successful. – Kousic Dec 20 '18 at 05:24
  • Can you share the windows log with us? May be that will help identify the proper issue you have. – Jaffer Wilson Dec 26 '18 at 08:02

4 Answers4

2

You will get "SERVICE_START_PENDING" if the the service takes too long to start (it means the service hasn't told Windows that it's started yet). "Too long" is up to the application issuing the start request. In the case of NSSM this appears to be very short, so if your system is under load the service is taking longer to start than NSSM expects.

There appears to be no way to tell NSSM how long a start or stop operation should take. For stop requests it even ignores its own shutdown timeout settings. Your option then for using NSSM is to compile from source and add a timeout option. Otherwise use a different tool, e.g. net:

net stop <service>
net start <service>
1

I believe that this issue was caused by the service itself.


It is highly probable that the service has bug and hang, fail, or take too much time to stop properly. Which raise issue when try to start it.


If the service fail: In my opinion, there is a potential workaround,by setting up a service recovery option in the service properties. Then select "Run a program" when the service failed. Then code a batch to get the PID of this service and kill it, then use NSSM to start it again.

In this batch you may use "SC query" command to check the service status:

C:\Windows>sc query "MyService" | find "STATE"
    STATE              : 3  STOP_PENDING

Note that if you use NSSM only to hide the windows, you may achieve the same goal with the Task Scheduler only.

In the "General" tab on task property. If you select "Run whether user is logged on or not", this will run from session 0 which won't show any window to you.

Then what you need to do on your scheduled task are, to kill / restart the target process itself as you do now. This will work more robustly.


If the service is not an official windows service but more an EXE program file (dev on your side) then converted to a services with NSSM, there is a high chance of failure. It could be better to rewrite/recompile the program as an actual Windows service.

A. STEFANI
  • 6,707
  • 1
  • 23
  • 48
  • "If the service is not an official windows service but more an EXE program file (dev on your side) then converted to a services with NSSM, there is a high chance of failure." why? – justinas Dec 22 '18 at 10:51
  • Dev a service, allow you to specify how it will react when onStop, onStart, event etc.. it allow you also to specify if the service canStop, canShutdown etc... take a look here https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-create-windows-services – A. STEFANI Dec 22 '18 at 22:13
0

The problem is that NSSM is timing out waiting for your service to start. Unfortunately it does not seem to be possible to provide NSSM with a custom timespan for the service start-up timeout.

One workaround is still use NSSM to install the service, but then use PowerShell to start and stop the service. PowerShell allows you to specify your own wait timeout (since you probably don't want your script to wait indefinitely).

$serviceName = 'My service'
$service = Get-Service $serviceName -ErrorAction Ignore
Write-Verbose "Starting service '$serviceName'."
$service.Start()
$waitTimeout = New-TimeSpan -Seconds 5
$service.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running, $waitTimeout)

You can read more about the PowerShell Get-Service command here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service

Brian Hinchey
  • 3,601
  • 1
  • 39
  • 36
0

Recently happened to me... not only I cannot restart the service but also stop it is not possible neither.

Lets kill it.

  1. Identify the process id (PID). Replace [SERVICE-NAME] with your service's name.
sc queryex "[SERVICE-NAME]"

You should get something like this:

SERVICE_NAME: xxxxxxxxx
        TYPE               : 30  WIN32
        STATE              : 4  RUNNING
                                (STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 4812
        FLAGS              :
  1. Manually kill the process. Replace [PID] with the value from the previous step.
taskkill /pid [PID] /f

This error is also related to

Windows could not stop the [SERVICE-NAME] service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.

Market
  • 450
  • 6
  • 17