Iain Patterson [Sun, 24 Nov 2013 20:37:26 +0000 (20:37 +0000)]
NSSM 2.21.
Iain Patterson [Sun, 24 Nov 2013 20:35:18 +0000 (20:35 +0000)]
Fixed parameters bug when installing from the GUI.
We were calling GetDlgItemText() on the wrong window. As a result,
trying to install a sevice with parameters set would fail with the
error message "No valid options were specified!"
Iain Patterson [Sat, 23 Nov 2013 15:44:31 +0000 (15:44 +0000)]
NSSM 2.20.
Iain Patterson [Sat, 23 Nov 2013 15:43:59 +0000 (15:43 +0000)]
Fixed bug when installing from the command line.
We forgot to set default values when installing from the command line.
Installing from the GUI worked.
Thanks Paul Spause.
Iain Patterson [Fri, 22 Nov 2013 16:23:53 +0000 (16:23 +0000)]
NSSM 2.19.
Iain Patterson [Fri, 22 Nov 2013 15:22:21 +0000 (15:22 +0000)]
Allow configuring output file truncation.
A new checkbox in the GUI allows specifying that stdout and stderr
should be truncated rather than appended. The registry must still
be used to set different disposition for each or to control the
disposition of stdin.
Iain Patterson [Fri, 22 Nov 2013 14:11:11 +0000 (14:11 +0000)]
Fixed environment when no newline was present.
If the user entered environment variables without a trailing newline we
might have been left with only one trailing NULL and therefore the
environment parameter would have been invalid. The path of least
resistance is to add two trailing NULLs unconditionally.
Iain Patterson [Fri, 22 Nov 2013 13:40:17 +0000 (13:40 +0000)]
Fix initial focus.
Ensure that the service name field has the initial input focus. It
already did for the install dialogue but didn't in the remove dialogue.
Iain Patterson [Fri, 22 Nov 2013 12:39:30 +0000 (12:39 +0000)]
Ensure CRLF is removed from GUI strings.
Windows 2000 will show funny characters where a string formatted with
message_string() contained a CRLF. Explicitly add NULL to the end of
the strings so that they are shown correctly on Windows 2000.
Iain Patterson [Fri, 22 Nov 2013 12:25:33 +0000 (12:25 +0000)]
Compiler food.
Make strip_basename() non-static so it can be used elsewhere,
particularly in cases where int and size_t are different sizes, ie on
32-bit builds.
Iain Patterson [Thu, 21 Nov 2013 18:39:07 +0000 (18:39 +0000)]
Set environment from the GUI at install time.
Added an extra Environment tab to set a newline-separated list of
environment variables to replace or be added to the service environment.
Input is validated by relaunching nssm itself with the proposed
environment set.
Iain Patterson [Thu, 21 Nov 2013 11:55:31 +0000 (11:55 +0000)]
Allow appending to the service environment.
The new registry value AppEnvironmentExtra allows defining a list of
environment variables which will be appended to the environment, as
opposed to those defined by the srvany-compatible AppEnvironment, which
replaces the environment.
Though it would serve no useful purpose beyond verifying whether or not
I went to the effort of writing a code path for it, it is possible to
define bother lists and have them behave intuitively.
Iain Patterson [Wed, 20 Nov 2013 15:15:09 +0000 (15:15 +0000)]
GUI overhaul.
We now have a much less sucky GUI with tabs, combo boxes and all sorts
of whizzbang stuff.
The new GUI allows setting most of the advanced features we support
directly from the service installer without having to poke about in the
registry.
Iain Patterson [Wed, 20 Nov 2013 12:14:15 +0000 (12:14 +0000)]
Pass parameters around in a data structure.
Instead of static variables and functions taking a dozen arguments we
now use a single data structure, nssm_service_t, for the service.
The code is easier to read and understand, especially when adding more
variables through to functions.
Iain Patterson [Wed, 20 Nov 2013 15:20:02 +0000 (15:20 +0000)]
Added set_expand_string() and set_number().
Helper functions to set REG_EXPAND_SZ and REG_DWORD values in the
registry.
Iain Patterson [Wed, 20 Nov 2013 15:14:56 +0000 (15:14 +0000)]
Added strip_basename() function.
Helper function to determine the parent directory of a path.
Iain Patterson [Sun, 17 Nov 2013 18:56:32 +0000 (18:56 +0000)]
Enforce maximum report delay when starting service.
We were not changing the service's state to running until the restart
throttling threshold had passed. However best practice is to change the
status to running or stopped as quickly as possible. Therefore we we
now report the status after no more than 20000 milliseconds regardless
of the throttle setting.
Iain Patterson [Fri, 15 Nov 2013 15:59:59 +0000 (15:59 +0000)]
NSSM 2.18.
Iain Patterson [Fri, 15 Nov 2013 15:50:17 +0000 (15:50 +0000)]
Allow the Escape key to close the GUI.
Turns out IDCANCEL is a magic resource name. If a button has that name
it automatically responds to Escape.
Iain Patterson [Fri, 15 Nov 2013 15:48:56 +0000 (15:48 +0000)]
Don't automatically close the GUI on error.
If a parameter in the GUI was missing or invalid we were closing the
dialogue and forcing the user to relaunch the installer/remover.
Instead we now loop until the service has successfully been
installed/removed or the user cancelled the operation.
Iain Patterson [Fri, 15 Nov 2013 15:44:46 +0000 (15:44 +0000)]
Spawn a separate thread for stop_service().
We must acknowledge a STOP or SHUTDOWN control promptly but the
termination of the application may take a significant amount of time if
one of the AppStopMethod* registry values is set.
We now spawn a separate thread to try to stop the process and to call
await_shutdown() while the main thread immediately acknowledges receipt
of the STOP request. Once the worker thread has updated the service
status to say that application is really stopped we will be
automatically cleaned up by the system.
If for some reason we can't spawn a new thread we log an error and
ignore user-supplied timeouts so as to ensure we tidy up promptly.
Iain Patterson [Fri, 15 Nov 2013 15:17:39 +0000 (15:17 +0000)]
Use await_shutdown().
Use the new await_shutdown() funtion to wait for the application to stop
rather than calling WaitForSingleObject() directly, so we can update the
service status periodically.
Iain Patterson [Fri, 15 Nov 2013 11:24:45 +0000 (11:24 +0000)]
Added await_shutdown() function.
The system expects service STOP requests to be honoured promptly. If
service shutdown will take longer than 30 seconds we must update the
service status checkpoint variable before then.
We also need to ensure that the service status wait hint time is
strictly increasing every time we update the checkpoint, otherwise the
service will be considered to be hung after 60 seconds.
Iain Patterson [Fri, 15 Nov 2013 11:21:58 +0000 (11:21 +0000)]
Prevent buffer overrun in log_event().
We were only expecting six message strings but we could possible receive
more.
Iain Patterson [Wed, 13 Nov 2013 15:35:20 +0000 (15:35 +0000)]
Allow overriding time to wait when trying to kill the application.
Three new registry entries can be used to specify a wait time in
milliseconds after attempting a stop method.
AppStopMethodConsole
AppStopMethodWindow
AppStopMethodThreads
The default for each remains the same, 1500ms.
Thanks Russ Holmann.
Iain Patterson [Wed, 13 Nov 2013 15:34:26 +0000 (15:34 +0000)]
Use override_milliseconds() to find throttle restart delay.
Use the new override_milliseconds() helper to find the override for the
amount of time to wait when throttling restarts.
Iain Patterson [Wed, 13 Nov 2013 15:32:40 +0000 (15:32 +0000)]
Added override_milliseconds() helper.
Helper function to retrieve a REG_DWORD value from the registry and
assign it to a variable, substituting a default value if the registry
entry is invalid or missing. The function is specifically tailored
toward setting a value in milliseconds, hence the name.
Iain Patterson [Wed, 13 Nov 2013 15:03:47 +0000 (15:03 +0000)]
Calculate service stop wait hint correctly.
The wait hint when changing the service status to stopped failed to take
into account the grace period after sending a Control-C event. It also
failed to consider the case where one or more stop methods were
disabled.
Iain Patterson [Fri, 15 Nov 2013 15:43:46 +0000 (15:43 +0000)]
Typos and formatting etc.
Iain Patterson [Tue, 12 Nov 2013 12:49:39 +0000 (12:49 +0000)]
NSSM 2.17.
Iain Patterson [Tue, 12 Nov 2013 13:32:37 +0000 (13:32 +0000)]
Fix tabbing between GUI fields.
The tab key didn't switch between fields in the GUI because we didn't
insert a call to IsDialogMessage() in the message loop.
Iain Patterson [Tue, 12 Nov 2013 12:31:22 +0000 (12:31 +0000)]
Try to throttle using a critical section.
The first implementation of service restart throttling used a condition
variable in a critical section to sleep for the required amount of time.
The implementation was changed to use a waitable timer because Windows
2000 does not support SleepConditionVariableCS() or
WakeConditionVariable().
Since we are now using LoadLibrary() and GetProcAddress() to use newer
functions dynamically without having to build OS-specific binaries, we
can now use a critical section where it's supported and fall back to a
waitable timer when running on Windows 2000.
Iain Patterson [Tue, 12 Nov 2013 10:50:21 +0000 (10:50 +0000)]
AttachConsole() isn't available in Windows 2000.
Instead of calling AttachConsole() directory use a function pointer in
the new global imports struct. It's safe to skip any attempt to attach
to the console when the function isn't available.
Iain Patterson [Thu, 31 Oct 2013 14:33:10 +0000 (14:33 +0000)]
Compiler food.
Silence any compiler warnings relating to the use of _(v)snprintf() -
not _(v)snprintf_s() - and type conversions.
Iain Patterson [Thu, 31 Oct 2013 14:28:43 +0000 (14:28 +0000)]
Updated nssm.dsp with missing dependencies.
Opening nssm.dsp in Visual Studio 2010 and accepting conversion to the
latest project format produced a project which would not build because
io.cpp, io.h, process.cpp, process.h and shlwapi.lib had not been added
to nssm.dsp.
They were present in nssm.vcproj from Visual Studio 2008 and it was
possible to load that project and convert to a format which worked.
Thanks Guy Brousseau.
Iain Patterson [Thu, 31 Oct 2013 13:23:55 +0000 (13:23 +0000)]
Try harder not to restart the application when stopping.
Try even harder to avoid race conditions whereby one thread reacts to an
application exit and performs a restart even after another thread has
committed to handling a stop control.
Thanks Runner Mei.
Iain Patterson [Thu, 31 Oct 2013 13:22:02 +0000 (13:22 +0000)]
Delay report that the service is running.
Wait until the application has been running for long enough to be exempt
from restart throttling before reporting a status of SERVICE_RUNNING to
the operating system.
Thanks Tom Saul.
Iain Patterson [Thu, 31 Oct 2013 13:14:31 +0000 (13:14 +0000)]
Skip some or all methods of stopping the application.
Use the AppStopMethodSkip bit field to specify any method(s) which
should not be employed when stopping the application.
Iain Patterson [Mon, 28 Oct 2013 20:51:56 +0000 (20:51 +0000)]
Fixed Control-C race.
A typo in kill_console() could cause the application to be restarted
when it was supposed to stop.
When kill_console() successfully generated a Control-C event and the
application exited, the function was supposed to return 0, indicating to
its parent function kill_process() that the application had been killed.
Due to a mistake in the test of WaitForSingleObject()'s return code,
kill_console() would instead return non-zero when the application exited
in response to Control-C. This would lead NSSM to continue with other
methods of trying to kill the application, leading to a race when
another thread detected that the application had exited without
recognising that it had done so in response to a stop control.
Thanks Barrett Lewis.
Iain Patterson [Tue, 22 Oct 2013 15:33:01 +0000 (16:33 +0100)]
Rudimentary file versioning.
Embed file version info in the resource file so that right-clicking the
executable shows the application version.
Unfortunately the version field must be formatted in a particular way so
we can't reuse the NSSM_VERSION #define from nssm.h but instead must
create a new #define and remember to update it when making a release.
Thanks fREW Schmidt.
Iain Patterson [Tue, 30 Jul 2013 21:39:40 +0000 (22:39 +0100)]
Fixed missing io.cpp and io.h.
The files were inadvertently not pushed along with the stream
redirection code.
Thanks Runner Mei.
Iain Patterson [Sat, 29 Jun 2013 07:28:42 +0000 (08:28 +0100)]
Notes on escaping quotes.
Brian Baxter points out that to install a service from the command
prompt with quotes in the options it is necessary to quote the quotes as
follows:
nssm install service "c:\Program Files\app.exe" """C:\Path with spaces"""
Iain Patterson [Thu, 25 Oct 2012 04:53:00 +0000 (21:53 -0700)]
Allow specifying output streams.
Allow starting the monitor application with one or more of stdin,
stdout and stderr redirected to a file or anything which can be
opened with CreateFile().
New registry values corresponding to CreateFile() arguments for
stdin (and analogously for stdout and stderr):
AppStdin: Path to open.
AppStdinShareMode: Sharing mode.
AppStdinCreationDisposition: Creation disposition.
AppStdinFlagsAndAtrributes: Flags and attributes.
All are optional. If no path is given for a particular stream it
will not be redirected. If a path is given but any of the other
values are omitted they will receive sensible defaults.
Iain Patterson [Thu, 25 Oct 2012 04:51:16 +0000 (21:51 -0700)]
Overload expand_parameter() like get_number().
Allow expand_parameter() to accept the optional must_exist flag.
Iain Patterson [Thu, 25 Oct 2012 04:47:12 +0000 (21:47 -0700)]
Added get_number() helper.
Retrieve a number (specifically an unsigned long) from the registry.
Allow the value to be optional by setting the must_exist parameter.
Overload the function definition such that must_exist can be omitted.
Iain Patterson [Tue, 19 Feb 2013 17:38:03 +0000 (09:38 -0800)]
Try to send Control-C event to application console.
Try to attach to the application's console and send a Control-C event when
shutting down. If a console exists, is successfully attached and successfully
sent the event, allow a grace period for the application to exit before sending
window messages or eventually calling TerminateProcess().
Now console applications which register shutdown handlers, such as java
launched from a batch file, have a chance to clean up and shut down gracefully.
Thanks Eric Cheldelin.
Iain Patterson [Mon, 3 Dec 2012 18:15:36 +0000 (10:15 -0800)]
Fix build on Visual Studio Express.
Visual Studio Express doesn't ship with MFC so the afxres.h header isn't
available. Since we don't actually use it, it's safe to replace that
header with a standard #include and #define.
Note that Visual Studio Express also ships without mc.exe so you will
also need to download the Windows SDK and set up your PATH in order to
build NSSM.
Iain Patterson [Mon, 3 Dec 2012 18:13:02 +0000 (10:13 -0800)]
Ignore INTERROGATE control.
NSSM periodically logs that it received an unhandled INTERROGATE
control. The control is sent by the system to request an update of the
service's status but NSSM always keeps the status up-to-date so no
action is needed on receipt of the control.
Rather than fill the logs with instances of such a message, NSSM will
now simply ignore the INTERROGATE control silently.
Iain Patterson [Sun, 2 Dec 2012 05:09:42 +0000 (00:09 -0500)]
NSSM 2.16.
Iain Patterson [Sun, 2 Dec 2012 02:22:08 +0000 (18:22 -0800)]
Fixed crash when stopping the service.
NSSM tidies up by looking for processes whose parent PID matches the PID
of the monitored application. Because process IDs are reused, however,
it's possible for NSSM to kill a process which was not a child of the
monitored application if that process had a now-exited parent process
whose PID was reused. On UNIX the PPID would show as 1 for an orphaned
process but under Windows, at least when querying a process with the
Toolhelp32 toolkit, we see the original PPID of the process even if the
parent is no longer running. Thus it is not sufficient to compare
parent PIDs when checking if a process was launched by our application.
In the worst case scenario NSSM could even terminate itself and trigger
a bluescreen.
When we find process with matching PPID we now also check that it was
created after our application was created and before our application
exited.
Iain Patterson [Thu, 19 Jul 2012 20:17:30 +0000 (21:17 +0100)]
NSSM 2.15.
Riccardo Gusmeroli [Thu, 19 Jul 2012 16:16:43 +0000 (17:16 +0100)]
Italian translations.
Resources and messages for version 2.14.
Signed-off-by: Iain Patterson <me@iain.cx>
Iain Patterson [Tue, 12 Jun 2012 15:18:31 +0000 (16:18 +0100)]
Fixed buffer length adding a service via the GUI.
The path to the monitored application and the arguments to the
application are both allowed to be sufficiently large to fit in the
maximum allowable registry value size. The GUI itself, however, was
restricting input fields to 256 characters.
Iain Patterson [Thu, 24 May 2012 21:46:07 +0000 (22:46 +0100)]
Whitespace.
Iain Patterson [Thu, 24 May 2012 21:16:47 +0000 (22:16 +0100)]
NSSM 2.14.
Iain Patterson [Thu, 24 May 2012 21:31:22 +0000 (22:31 +0100)]
Missing text typo.
Iain Patterson [Thu, 24 May 2012 21:15:13 +0000 (22:15 +0100)]
Fixed default language.
The GUI was appearing in French if the display language was set to
anything other than English. Ensure English is the default language by
defining the English resources as English US not English UK.
Spotted by Emilio Frini but apologies must go to François-Régis Tardy
who included the change along with his translations. I didn't apply it
because I didn't realise that things wouldn't work without it.
Iain Patterson [Thu, 24 May 2012 12:34:53 +0000 (13:34 +0100)]
Log exit messages more intuitively.
In the case where the application crashed and NSSM then cleaned up its
child processes the events logged were confusing. First we'd log that
we were going to kill the process tree with exit code X then we'd log
that the service had ended with exit code X.
Logging that the application exited before doing the process tree kill
makes it clearer that the cleanup is in response to the application
exit.
Iain Patterson [Thu, 24 May 2012 11:44:56 +0000 (12:44 +0100)]
NSSM 2.13.
Iain Patterson [Sun, 20 May 2012 13:58:46 +0000 (14:58 +0100)]
Windows 2000 optimisation.
Windows 2000 takes a few seconds to time out when trying and failing to
connect to the service manager if NSSM was run with no arguments.
Check for stdin first. It won't exist if we are running in a service
context so we can skip the connection attempt unless we're unsure.
Iain Patterson [Sun, 20 May 2012 11:11:51 +0000 (12:11 +0100)]
Localised (almost) all messages.
Use FormatMessage() to localise messages printed to the console or shown
in MessageBoxes.
The new messages are allocated IDs starting at 501 so as not to clash
with event log messages starting at 1001.
Once again French translations were provided by François-Régis Tardy.
François-Régis Tardy [Sat, 19 May 2012 12:54:17 +0000 (13:54 +0100)]
Updated translation from François-Régis Tardy.
Signed-off-by: Iain Patterson <me@iain.cx>
Iain Patterson [Tue, 15 May 2012 10:08:34 +0000 (11:08 +0100)]
Handle running without administrator privileges.
If the service is configured to run as an unprivileged user NSSM will
not be able to perform certain tasks which are not critical and will
therefore log some errors which can be ignored.
It will not be able to register itself as an event log source.
It will not be able to create a default AppExit key.
It will not be able to configure service failure handling.
Try to perform these tasks where first installing the service (which
we are guaranteed to do with administrator rights) as well as at
runtime, and don't log the errors if the runtime actions can't be
performed.
Iain Patterson [Tue, 15 May 2012 10:05:57 +0000 (11:05 +0100)]
Fixed incomplete set_service_recovery().
A rogue return prevented set_service_recovery() from actually doing anything.
Also we weren't checking for failure in ChangeServiceConfig2(). We expect
ERROR_INVALID_LEVEL on pre-Vista Windows but other errors were not detected.
French translation by François-Régis Tardy.
Iain Patterson [Mon, 14 May 2012 13:30:08 +0000 (14:30 +0100)]
Log that we received control messages.
Send a message to the event log when we receive a service control.
Use a fake message for starting a service so we can reuse code.
No SERVICE_CONTROL_START control is defined or used by the Windows
API.
French translations by François-Régis Tardy.
François-Régis Tardy [Sun, 13 May 2012 08:48:03 +0000 (09:48 +0100)]
French translations.
Resources and messages for version 2.12.
Signed-off-by: Iain Patterson <me@iain.cx>
Iain Patterson [Mon, 7 May 2012 12:01:25 +0000 (13:01 +0100)]
NSSM 2.12.
Iain Patterson [Mon, 7 May 2012 12:00:57 +0000 (13:00 +0100)]
Windows 2000 compatibility notes.
Iain Patterson [Wed, 4 Apr 2012 21:30:06 +0000 (22:30 +0100)]
NSSM 2.11.
Iain Patterson [Wed, 4 Apr 2012 21:00:08 +0000 (22:00 +0100)]
Removed run hack.
Previously we used to attempt to run as a service only when the "run"
argument was given, and printed a usage message if no arguments were
provided.
A more appropriate strategy is to check for StartServiceCtrlDispatcher()
returning ERROR_FAILED_SERVICE_CONTROLLER_CONNECT, as that means the
application is not running in a service context.
As a result we no longer write the undocumented "run" argument to the
registry when installing a service. Technically this means that we
sacrifice backward compatibility with older versions.
Iain Patterson [Sun, 1 Apr 2012 10:35:54 +0000 (11:35 +0100)]
Support srvany's AppEnvironment registry value.
Allow setting one or more environment variables for the application by
creating the AppEnvironment value of type REG_MULTI_SZ. Each string
should be of the form KEY=VALUE. VALUE may be omitted to set an empty
environment variable but the equals sign must be present.
This support is for compatibility with srvany. In accordance with the
documented behaviour of srvany, only environment variables specified in
AppEnvironment will be passed to the service. Any other variables, even
system variables such as %PATH%, will be ignored if they are not
explicitly listed.
Note that Windows supports adding environment variables to the service's
existing environment by creating the Environment value (also of type
REG_MULTI_SZ) under HKLM\SYSTEM\CurrentControlSet\Services\<service>
instead. It is recommended that new services use this standard
functionality rather than AppEnvironment.
Thanks Rob Sharp.
Iain Patterson [Sun, 1 Apr 2012 09:48:52 +0000 (10:48 +0100)]
Typo.
Iain Patterson [Tue, 11 Oct 2011 10:03:03 +0000 (11:03 +0100)]
NSSM 2.10.
Iain Patterson [Sun, 6 Mar 2011 10:23:03 +0000 (10:23 +0000)]
New URL and icon.
NSSM has a new website at http://nssm.cc/ and slightly-better red N
icon. Contributions of a useful icon and logo would be gratefully
received. Perhaps some kind of executable/service cogs mashup.
Iain Patterson [Sat, 8 Oct 2011 10:02:51 +0000 (11:02 +0100)]
Check for administrator privileges.
If nssm is run without an administrator token it will fail to install or
remove services. Check for the token and bomb out early rather than
waste the user's time filling in the form only to find the service can't
be managed.
Iain Patterson [Sat, 8 Oct 2011 09:02:24 +0000 (10:02 +0100)]
Fixed compilation of messages.mc.
Compiling messages.mc failed in paths containing a space. Eugene
Lifshitz advised how to construct a commandline which would work
in such paths.
Iain Patterson [Mon, 3 Oct 2011 20:53:26 +0000 (21:53 +0100)]
More CreateProcess() fun.
Correctly handle the case where the application executable is under
a path which contains space and an executable sharing the initial
part of that path (up to a space) exists.
A (contrived) example is when Application is
C:\stuff\app lications\foo.exe
and C:\stuff\app.exe also exists.
Thanks Eugene Lifshitz.
Iain Patterson [Tue, 1 Mar 2011 22:25:32 +0000 (22:25 +0000)]
Added a changelog.
Iain Patterson [Mon, 28 Feb 2011 17:53:48 +0000 (17:53 +0000)]
NSSM 2.9.
Iain Patterson [Mon, 28 Feb 2011 17:35:20 +0000 (17:35 +0000)]
Timer safety.
Check we actually have a waitable timer before trying to use it.
Use the correct compiler food to ensure that 256000 milliseconds is
converted to a LARGE_INTEGER correctly.
Iain Patterson [Mon, 28 Feb 2011 11:48:11 +0000 (11:48 +0000)]
Fix pre-Vista compatibility.
SleepConditionVariableCS() isn't available on Windows versions
prior to Vista. Use a waitable timer instead.
Iain Patterson [Sat, 26 Feb 2011 14:47:13 +0000 (14:47 +0000)]
NSSM 2.8.
Iain Patterson [Sat, 26 Feb 2011 12:39:43 +0000 (12:39 +0000)]
Allow configuring throttling threshold.
Tweak minimum time for which a service must run by setting the threshold
number of milliseconds in AppThrottle (REG_DWORD).
Iain Patterson [Sat, 26 Feb 2011 11:52:39 +0000 (11:52 +0000)]
Removed some legacy stuff.
What was #define GUI even for?
Why #define snprintf _snprintf in one file where we're using actual
_snprintf everywhere else?
Iain Patterson [Sat, 26 Feb 2011 11:51:31 +0000 (11:51 +0000)]
Corrected restart throttling documentation.
The documentation said that the maximum throttle time was 60 seconds
whereas in fact it is 256 seconds. The documentation now describes
it as four minutes.
Iain Patterson [Sat, 26 Feb 2011 11:50:13 +0000 (11:50 +0000)]
Thread safety.
Multiple threads might call error_string() so a static buffer is
dangerous. Use TLS for a safe buffer.
Iain Patterson [Thu, 17 Feb 2011 00:05:06 +0000 (00:05 +0000)]
Read registry before each restart.
Read Application, AppDirectory and AppParameters before each restart so
a change to any one doesn't require restarting NSSM itself.
Iain Patterson [Thu, 17 Feb 2011 00:00:09 +0000 (00:00 +0000)]
Tidyup TerminateProcess().
TerminateProcess() will fail if the process already died for some
reason. Don't log an error in this case.
Log a more interesting message when recursing into kill_process_tree().
Iain Patterson [Wed, 16 Feb 2011 23:51:22 +0000 (23:51 +0000)]
Fix event logging.
Some messages weren't being logged properly. One common reason was that
one or more arguments to log_event() were longs but were interpreted
as strings. Create a temporary buffer and sprintf the numbers to fix
that.
The other reason was that GetLastError() returns a long where a string
was expected. Restore the previously removed error_string() function to
convert it into an error message.
Iain Patterson [Wed, 16 Feb 2011 23:48:31 +0000 (23:48 +0000)]
Use GetWindowsDirectory() instead of %SYSTEMROOT%.
Though unlikely, it's possible that %SYSTEMROOT% might be undefined.
Iain Patterson [Wed, 16 Feb 2011 23:46:27 +0000 (23:46 +0000)]
Strip quotes from directory name.
Windows directories aren't allowed to contain quotes so CreateProcess()
will fail if the AppDirectory is quoted. Note that it succeeds even if
Application itself is quoted as the application plus parameters are
interpreted as a command line.
Iain Patterson [Tue, 8 Feb 2011 22:55:01 +0000 (22:55 +0000)]
Fixed arguments when installing a service.
Only the first flag supplied on the command line was being added to
the registry.
Iain Patterson [Thu, 3 Feb 2011 19:00:19 +0000 (19:00 +0000)]
Don't leak memory reading REG_SZ values.
Iain Patterson [Thu, 3 Feb 2011 18:43:02 +0000 (18:43 +0000)]
Throttle restarts.
Back off from restarting the application immediately if it starts
successfully but exits too soon.
Handle resume messages from the service console to restart the
application immediately even if it is throttled.
Use service status wait hints to tell the operating system how long
start, stop and resume actions are likely to take.
Iain Patterson [Thu, 3 Feb 2011 00:22:30 +0000 (00:22 +0000)]
Try to kill the process tree gracefully.
Before calling TerminateProcess() on all processes assocatiated with
the monitored application, enumerate all windows and threads and
post appropriate messages to them. If the application bothers to
listen for such messages it has a chance to shut itself down gracefully.
If the application ignores this chance to do the right thing it's
fair game for termination.
Iain Patterson [Tue, 25 Jan 2011 22:52:03 +0000 (22:52 +0000)]
NSSM 2.7.
Iain Patterson [Tue, 25 Jan 2011 22:38:05 +0000 (22:38 +0000)]
Handle missing registry values.
Warn if AppParameters is missing.
Warn if AppDirectory is missing or unset and choose a fallback directory.
First try to find the parent directory of the application. If that
fails, eg because the application path is just "notepad" or something,
expand %SYSTEMROOT%. If THAT fails it's time to give up and go home.
Thanks Arve Knudsen.
Iain Patterson [Tue, 25 Jan 2011 22:34:48 +0000 (22:34 +0000)]
Messages for kill_process_tree().
Iain Patterson [Tue, 25 Jan 2011 10:21:20 +0000 (10:21 +0000)]
Kill process tree when stopping service.
Ensure that all child processes of the monitored application are
killed when the service stops by recursing through all running
processes and terminating those whose parent is the application
or one of its descendents.
Iain Patterson [Fri, 19 Nov 2010 11:16:04 +0000 (11:16 +0000)]
NSSM 2.6.