nssm.git
11 years agoNSSM 2.12. v2.12
Iain Patterson [Mon, 7 May 2012 12:01:25 +0000 (13:01 +0100)]
NSSM 2.12.

11 years agoWindows 2000 compatibility notes.
Iain Patterson [Mon, 7 May 2012 12:00:57 +0000 (13:00 +0100)]
Windows 2000 compatibility notes.

12 years agoNSSM 2.11. v2.11
Iain Patterson [Wed, 4 Apr 2012 21:30:06 +0000 (22:30 +0100)]
NSSM 2.11.

12 years agoRemoved run hack.
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.

12 years agoSupport srvany's AppEnvironment registry value.
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.

12 years agoTypo.
Iain Patterson [Sun, 1 Apr 2012 09:48:52 +0000 (10:48 +0100)]
Typo.

12 years agoNSSM 2.10. v2.10
Iain Patterson [Tue, 11 Oct 2011 10:03:03 +0000 (11:03 +0100)]
NSSM 2.10.

12 years agoNew URL and icon.
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.

12 years agoCheck for administrator privileges.
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.

12 years agoFixed compilation of messages.mc.
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.

12 years agoMore CreateProcess() fun.
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.

13 years agoAdded a changelog.
Iain Patterson [Tue, 1 Mar 2011 22:25:32 +0000 (22:25 +0000)]
Added a changelog.

13 years agoNSSM 2.9. v2.9
Iain Patterson [Mon, 28 Feb 2011 17:53:48 +0000 (17:53 +0000)]
NSSM 2.9.

13 years agoTimer safety.
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.

13 years agoFix pre-Vista compatibility.
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.

13 years agoNSSM 2.8. v2.8
Iain Patterson [Sat, 26 Feb 2011 14:47:13 +0000 (14:47 +0000)]
NSSM 2.8.

13 years agoAllow configuring throttling threshold.
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).

13 years agoRemoved some legacy stuff.
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?

13 years agoCorrected restart throttling documentation.
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.

13 years agoThread safety.
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.

13 years agoRead registry before each restart.
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.

13 years agoTidyup TerminateProcess().
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().

13 years agoFix event logging.
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.

13 years agoUse GetWindowsDirectory() instead of %SYSTEMROOT%.
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.

13 years agoStrip quotes from directory name.
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.

13 years agoFixed arguments when installing a service.
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.

13 years agoDon't leak memory reading REG_SZ values.
Iain Patterson [Thu, 3 Feb 2011 19:00:19 +0000 (19:00 +0000)]
Don't leak memory reading REG_SZ values.

13 years agoThrottle restarts.
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.

13 years agoTry to kill the process tree gracefully.
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.

13 years agoNSSM 2.7. v2.7
Iain Patterson [Tue, 25 Jan 2011 22:52:03 +0000 (22:52 +0000)]
NSSM 2.7.

13 years agoHandle missing registry values.
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.

13 years agoMessages for kill_process_tree().
Iain Patterson [Tue, 25 Jan 2011 22:34:48 +0000 (22:34 +0000)]
Messages for kill_process_tree().

13 years agoKill process tree when stopping service.
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.

13 years agoNSSM 2.6. v2.6
Iain Patterson [Fri, 19 Nov 2010 11:16:04 +0000 (11:16 +0000)]
NSSM 2.6.

13 years agoRemoved incorrect ExpandEnvironmentStrings() error.
Iain Patterson [Fri, 19 Nov 2010 07:31:35 +0000 (07:31 +0000)]
Removed incorrect ExpandEnvironmentStrings() error.

A log_event() call was inadvertently left in the code causing an error
to be set to the eventlog saying that ExpandEnvironmentStrings() had
failed when it had actually succeeded.

13 years agoNSSM 2.5. v2.5
Iain Patterson [Sat, 25 Sep 2010 15:00:42 +0000 (16:00 +0100)]
NSSM 2.5.

13 years agoExpand environment strings in parameters.
Iain Patterson [Sat, 25 Sep 2010 14:52:07 +0000 (15:52 +0100)]
Expand environment strings in parameters.

Allow use of REG_EXPAND_SZ values in the registry.

13 years agoDon't suicide on exit status 0.
Iain Patterson [Sat, 25 Sep 2010 13:37:28 +0000 (14:37 +0100)]
Don't suicide on exit status 0.

Suiciding when the application exits 0 will cause recovery actions to be
taken.  Usually this is inappropriate.  Only suicide if there is an
explicit AppExit value for 0 in the registry.

Technically such behaviour could be abused to do something like run a
script after successful completion of a service but in most cases a
suicide is undesirable when no actual failure occurred.

13 years agoHandle startup failure.
Iain Patterson [Sat, 25 Sep 2010 09:05:09 +0000 (10:05 +0100)]
Handle startup failure.

Don't hang if startup parameters couldn't be determined.
Instead, signal that the service entered the STOPPED state.
Set START_PENDING state prior to actual startup.

13 years agoNSSM 2.4. v2.4
Iain Patterson [Thu, 23 Sep 2010 15:30:41 +0000 (16:30 +0100)]
NSSM 2.4.

13 years agoEnsure systems recovery actions can happen.
Iain Patterson [Thu, 23 Sep 2010 14:27:14 +0000 (15:27 +0100)]
Ensure systems recovery actions can happen.

In Windows versions earlier than Vista the service manager would only
consider a service failed (and hence eligible for recovery action) if
the service exited without setting its state to SERVICE_STOPPED, even if
it signalled an error exit code.
In Vista and later the service manager can be configured to treat a
graceful shutdown with error code as a failure but this is not the
default behaviour.

Try to configure the service manager to use the new behaviour when
starting the service so users who set AppExit to Exit can use recovery
actions as expected.

Also recognise the new AppExit option Suicide for use on pre-Vista
systems.  When AppExit is Suicide don't stop the service but exit
inelegantly, which should be seen as a failure.

14 years agoNSSM 2.3 v2.3
Iain Patterson [Wed, 21 Apr 2010 21:56:33 +0000 (22:56 +0100)]
NSSM 2.3

14 years agoFix path lengths.
Iain Patterson [Wed, 21 Apr 2010 21:53:55 +0000 (22:53 +0100)]
Fix path lengths.

Some buffers were being limited to MAX_PATH characters when higher
limits were more appropriate.
For example the maximum length of a command line is documented as 32768
characters with the application name part limited to MAX_PATH.
Long applications paths and arguments could be truncated when written to
the registry.

Thanks Joel Reingold.

14 years agoLog messages properly.
Iain Patterson [Tue, 20 Apr 2010 21:56:55 +0000 (22:56 +0100)]
Log messages properly.

Format messages from resource.  Use NSSM binary as the message source.
Note that replacing the binary is prevented if the event viewer is open.

14 years agoCompile messages.
Iain Patterson [Mon, 19 Apr 2010 22:17:55 +0000 (23:17 +0100)]
Compile messages.

Don't spam the event log with warnings about not finding application
messages.
Every message currently uses the default event ID 1.

14 years agoDon't break the window size.
Iain Patterson [Mon, 19 Apr 2010 20:57:27 +0000 (21:57 +0100)]
Don't break the window size.

The dialogue was being moved incorrectly, resulting in it inadvertently
changing size.

14 years agoNSSM 2.2. v2.2
Iain Patterson [Sun, 4 Apr 2010 17:34:48 +0000 (18:34 +0100)]
NSSM 2.2.

14 years agoDecide how to handle application exit.
Iain Patterson [Sun, 4 Apr 2010 16:46:17 +0000 (17:46 +0100)]
Decide how to handle application exit.

When the service exits with exit code n look in
HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppExit\<n>,
falling back to the unnamed value if no such code is listed.  Parse the
(string) value of this entry as follows:

    Restart: Start the application again (NSSM default).
    Ignore:  Do nothing (srvany default).
    Exit:    Stop the service.

14 years agoNSSM 2.1. v2.1
Iain Patterson [Mon, 28 Dec 2009 11:51:00 +0000 (06:51 -0500)]
NSSM 2.1.

14 years agoNSSM 2.0. v2.0
Iain Patterson [Sun, 10 Sep 2006 01:33:00 +0000 (21:33 -0400)]
NSSM 2.0.

14 years agoNSSM 1.0. v1.0
Iain Patterson [Fri, 30 May 2003 18:32:00 +0000 (14:32 -0400)]
NSSM 1.0.

14 years agoInitial commit.
Iain Patterson [Fri, 30 May 2003 18:32:00 +0000 (14:32 -0400)]
Initial commit.