kirillkovalenko / nssm

Non-Sucking Service Manager
https://nssm.cc
737 stars 126 forks source link

Nssm doesn't actually quit out of batch scripts that are run as a service #4

Closed Tanz0rz closed 5 years ago

Tanz0rz commented 8 years ago

Nssm sends the kill signal which pauses the script, and then eventually crushes it when NSSM reaches the final timeout and triggers the TerminateProcess() call.

I am fairly certain that this is happening because NSSM sends only one Ctrl+C call to the script. In batch scripts, Ctrl+C gives the user this message:

"Terminate batch job (Y/N)?"

In this state, the script is paused, but is still very much alive.

Here is the summary of a bare-bones setup to reproduce this issue

Hook Nssm up to a batch script that has the following contents:

SET LOGFILE="servicerunning.log"

:loop

echo alive..... >> %LOGFILE% 2>&1 
timeout /t 1

goto loop

Use the "Shutdown" tab in the nssm gui to give the program a decent amount of time to shutdown.

Start the service and watch it write to the file. Attempt to stop the service. The script will stop writing to the log file, but the status in the Windows "Services" view will show the state of the service as "Stopping" until the max timeout gets hit and the cmd windows is terminated.

EDIT: I seem to have found a potential work-around for this issue. Redirecting the stdin to nul has proven to show some promise (batchscript.bat < nul). I have used the fix in my production environment and have not hit any issues so far.

kirillkovalenko commented 7 years ago

I'm not an owner of this code, Iain Patterson is. This repo is just a mirror of Iain's original repo at https://nssm.cc

kirillkovalenko commented 5 years ago

THIS REPO IS NOT OWNED OR MONITORED BY THE AUTHOR OF THIS APPLICATION! REACH OUT TO HIM AT me@iain.cx