3

I have set up a task in Windows Task Scheduler to run at a specific time each day. The task simply executes a batch file I've created to restart my Windows service. This is the contents of that file:

net stop "MyService"
net start "MyService"

This seems to work well for the most part, but occasionally the service will actually pause itself, rather than stop/start. I will come back to it later on and it will just be sitting there, paused.

Why would task scheduler pause my service, rather than start it, and how can I remedy that?

2
  • Sounds like the service is faulty, or at least doing something unexpected. Anything in the Event Logs related to this? Did you write this service? If so, add some logging to it. Oct 2, 2014 at 20:32
  • @Ƭᴇcʜιᴇ007 Indeed, I did. I added some logging, but nothing obvious came out of it. It is an executable converted to a service with nssm, if that tells you anything more
    – Jim
    Oct 2, 2014 at 20:32

3 Answers 3

1

EXE's converted to a services by utilities like NSSM are fraught with chances of failure.

Even NSSM points this out on their home page:

"...if your application is well-behaved you can configure nssm to absolve all responsibility for restarting it and let Windows take care of recovery actions."

Sounds like your application is not "well behaved".

Either try using NSSM to stop/start and restart the service, or if that doesn't help, rewrite/recompile the program as an actual Windows service.

1

I believe that this issue was caused by the service itself, but there is a workaround with "SC query" command.

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

It's possible to append a check routine in your batch file to double-check the service status after having some interval, kill the service process (taskkill /f) if it's hung and restart the service (net start).

In addition, if you use NSSM in order to hide the window, you don't have to use NSSM and you may achieve the same goal with Task Scheduler only. (But if you aim something different - please ignore the following.)

task scheduler property

This is a part of "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.

1

You might see this if you've used NSSM to make logstash a service, and you have updated your Java installation since you created the .bat file that NSSM is using to start your service, you may find the path to java.exe in your batch file is no longer valid.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .