nssm.git
10 years agoAllow service editing on the command line.
Iain Patterson [Wed, 1 Jan 2014 12:41:02 +0000 (12:41 +0000)]
Allow service editing on the command line.

Individual service parameters can now be queried or edited on the
command line.  The syntax is designed to be intuitive and is
described in some detail in the README.  Some examples follow:

    nssm get Selenium Application

    nssm get "My Batch Job" AppExit 0

    nssm get Jenkins AppEnvironmentExtra CLASSPATH

    nssm get Netlogon ImagePath

    nssm set UT2004 Application C:\Games\UT2004\System\UCC.exe

    nssm set UT2004 AppParameters server

    nssm set UT2004 AppExit Default Exit

    nssm set Jenkins ObjectName DOMAIN\ci correct horse battery staple

    nssm set "My Batch Job" AppExit 0 Exit

    nssm set WowzaMediaServer362 Start SERVICE_DELAYED_START

    nssm set UT2004 Type SERVICE_INTERACTIVE_PROCESS

    nssm reset UT2004 AppEnvironment

    nssm reset UT2004 ObjectName

10 years agoAdded str_number().
Iain Patterson [Wed, 1 Jan 2014 12:39:20 +0000 (12:39 +0000)]
Added str_number().

Wrapper function around _tcstoul().

10 years agoBe more Windowsy.
Iain Patterson [Wed, 1 Jan 2014 12:37:07 +0000 (12:37 +0000)]
Be more Windowsy.

Now that the GUI is more functional, it should behave more like a real
Windows application.  That means having an icon and modal messageboxes.

10 years agoFixed srvany-compatible environment checkbox.
Iain Patterson [Wed, 1 Jan 2014 12:02:06 +0000 (12:02 +0000)]
Fixed srvany-compatible environment checkbox.

The checkbox was inverted.  If we were replacing the environment, like
srvany does, it was unchecked, suggesting that the environment would be
appended.

10 years agoAdded format_environment() and unformat_environment().
Iain Patterson [Wed, 1 Jan 2014 12:00:33 +0000 (12:00 +0000)]
Added format_environment() and unformat_environment().

Added new functions to convert an environment block, with each KEY=value
pair separated by NULL NULL, to and from a string, with the pairs
separated by CRLF.

10 years agoAdded get_service_description().
Iain Patterson [Tue, 31 Dec 2013 16:11:08 +0000 (16:11 +0000)]
Added get_service_description().

New function to set or unset a service's description.

10 years agoAdded open_registry() function.
Iain Patterson [Tue, 31 Dec 2013 14:04:00 +0000 (14:04 +0000)]
Added open_registry() function.

Moved RegOpenKeyEx() and RegCreateKeyEx() to a separate function
open_registry().

10 years agoAdded get_service_username().
Iain Patterson [Mon, 30 Dec 2013 13:55:18 +0000 (13:55 +0000)]
Added get_service_username().

New function to get the service username.

10 years agoAdded get_service_description().
Iain Patterson [Mon, 30 Dec 2013 13:43:15 +0000 (13:43 +0000)]
Added get_service_description().

New function to get the service description.

10 years agoAdded get_service_startup().
Iain Patterson [Mon, 30 Dec 2013 11:50:20 +0000 (11:50 +0000)]
Added get_service_startup().

New function to retrieve the service startup type.

10 years agoRemember to free info after QueryServiceConfig2().
Iain Patterson [Mon, 30 Dec 2013 11:20:07 +0000 (11:20 +0000)]
Remember to free info after QueryServiceConfig2().

We weren't freeing the SERVICE_CONFIG_DELAYED_AUTO_START_INFO buffer
after checking for delayed auto start.

10 years agoMoved QueryServiceConfig() to a separate function.
Iain Patterson [Mon, 30 Dec 2013 10:56:19 +0000 (10:56 +0000)]
Moved QueryServiceConfig() to a separate function.

The new function query_service_config() will return a pointer to a
QUERY_SERVICE_CONFIG data structure.

10 years agoDetect if we were double-clicked.
Iain Patterson [Sun, 29 Dec 2013 17:29:21 +0000 (17:29 +0000)]
Detect if we were double-clicked.

Because we are compiled as a console subsystem application, if the user
double-clicks the executable it will pop up a new console window.  Then,
since no arguments were passed, we will dump a usage message which the
user won't have time to read, and exit.

We now detect this situation and redirect the usage message to a popup.

There are three likely cases to handle.

If we are running in a service context there won't be a console window.
GetConsoleWindow() will return a null handle.

If were launched from a command window, the process ID owning the
console handle will be different from as our process ID.

If the process IDs are the same, we were started with a new console.  We
call FreeConsole() to close it and subsequently direct the usage message
to a message box.

10 years agoFixed loading localised resources.
Iain Patterson [Sun, 29 Dec 2013 17:25:54 +0000 (17:25 +0000)]
Fixed loading localised resources.

We weren't loading the correct resources for non-English languages when
compiled as a Unicode application.

We now explicitly call FindResourceEx(), LoadResource() and
CreateDialogIndirectParam() to ensure the appropriate windows are shown.

We now explicitly pass GetUserDefaultLangID() to FormatMessage(),
falling back to language neutral if it fails.

Resources and messages are now explicitly UTF-16LE.  That means that git
will treat them as binary and refuse to diff them.  To work around that,
add the following to .git/info/attributes:

    *.mc diff=utf16
    *.rc diff=utf16

and the following to .git/config:

    [diff "utf16"]
     textconv = "iconv -f utf-16le -t utf-8"

10 years agoFixed arguments to mbstowcs_s().
Iain Patterson [Sat, 28 Dec 2013 17:02:30 +0000 (17:02 +0000)]
Fixed arguments to mbstowcs_s().

The third argument to mbstowcs_s() is a buffer size not a character
count.

10 years agoGrant SeServiceLogonRight.
Iain Patterson [Sat, 28 Dec 2013 16:41:06 +0000 (16:41 +0000)]
Grant SeServiceLogonRight.

If the service is to be run under a user account, ensure that the
account has the right to log on as a service.

10 years agoFixed print_message() when out of memory.
Iain Patterson [Sat, 28 Dec 2013 16:33:38 +0000 (16:33 +0000)]
Fixed print_message() when out of memory.

We were passing NSSM_EVENT_OUT_OF_MEMORY to print_message() but
print_message() expects printf-style message strings and NSSM_EVENT_*
strings use %1, %2 etc.  Instead we now use the new message
NSSM_MESSAGE_OUT_OF_MEMORY when printing memory errors to the console.

10 years agoFixed changing service password.
Iain Patterson [Sat, 28 Dec 2013 16:30:42 +0000 (16:30 +0000)]
Fixed changing service password.

Ensure that we still process a password change even if the username is
the same.
Ensure we handle all errors from edit_service().

10 years agoSafer version.h creation.
Iain Patterson [Sat, 28 Dec 2013 16:13:34 +0000 (16:13 +0000)]
Safer version.h creation.

Use a temporary file so Visual Studio doesn't detect a timestamp change
on the file and trigger a rebuild.

10 years agoMore detailed file properties.
Iain Patterson [Fri, 27 Dec 2013 14:15:21 +0000 (14:15 +0000)]
More detailed file properties.

Add build information, comments and copyright to the executable's
version info fields.

10 years agoGenerate version information as part of the build.
Iain Patterson [Thu, 26 Dec 2013 19:30:47 +0000 (19:30 +0000)]
Generate version information as part of the build.

Use git (if it's available) to create a major and minor version number
based on the most recent tag name.  If we are not building from a
tagged commit, use the commit count since the last tag as the subminor
version.  If Jenkins is being used for the build, use the build number
as the subsubminor version.

10 years agoDisplay canonical service name.
Iain Patterson [Thu, 26 Dec 2013 19:28:56 +0000 (19:28 +0000)]
Display canonical service name.

When editing or deleting a service we get the service information using the
name provided by the user.  The name is case-insensitive but case-preserving.
Use GetServiceKeyName() to retrieve the canonical name and display that
in any messages containing the service name.

10 years agoAllow editing services.
Iain Patterson [Mon, 23 Dec 2013 18:25:28 +0000 (18:25 +0000)]
Allow editing services.

"nssm edit <service>" brings up a GUI to edit an existing service.
Services not managed by NSSM can also be edited but only system
properties such as the display name will appear in the GUI.

10 years agoSafer set_environment().
Iain Patterson [Tue, 24 Dec 2013 11:56:27 +0000 (11:56 +0000)]
Safer set_environment().

Ensure that the return parameters are set safely when things go wrong.

10 years agoFixed popup_message().
Iain Patterson [Tue, 24 Dec 2013 11:54:31 +0000 (11:54 +0000)]
Fixed popup_message().

The second argument to _vsntprintf_s() is a count not a size.
The fallback errors weren't massively helpful.
The message buffer is too small for some larger messages.

10 years agoAdded delete_createfile_parameter().
Iain Patterson [Tue, 24 Dec 2013 00:33:48 +0000 (00:33 +0000)]
Added delete_createfile_parameter().

Function to remove a value related to I/O redirection from the registry.

10 years agoDisable interactive checkbox when a user is set.
Iain Patterson [Mon, 23 Dec 2013 18:21:12 +0000 (18:21 +0000)]
Disable interactive checkbox when a user is set.

A service can only interact with the desktop when running as LOCALSYSTEM
so disable the checkbox for that option when a user account is set.

10 years agoStore I/O redirection and environment options.
Iain Patterson [Mon, 23 Dec 2013 17:01:47 +0000 (17:01 +0000)]
Store I/O redirection and environment options.

Previously we queried I/O redirection and environment options from the
registry when starting the service.  We now add support for being able
to query those options and store them in the service data structure at
any time.  This will allow us to edit services later.

10 years agoChanged arguments to nssm_gui().
Iain Patterson [Mon, 23 Dec 2013 16:14:22 +0000 (16:14 +0000)]
Changed arguments to nssm_gui().

The second argument to nssm_gui() is now an nssm_service_t pointer
rather than a string.  This will allow the function to be extended later
to edit existing services.

10 years agoSet log on details in the GUI.
Iain Patterson [Sun, 22 Dec 2013 12:05:48 +0000 (12:05 +0000)]
Set log on details in the GUI.

The GUI can now set service logon and desktop interactive details.

10 years agoGUI tweaks.
Iain Patterson [Sun, 22 Dec 2013 10:36:09 +0000 (10:36 +0000)]
GUI tweaks.

The check_method_timeout() static function was used for processing
timeouts in milliseconds, hence the name.  We are now reusing it to
check arbitrary numbers, so the name is no longer appropriate.

Instead of having checkboxes to enable or disable file rotation
parameters we enable or disable the editboxes where the values are
entered, based on the state of the rotation checkbox.

Similarly, the editboxes for shutdown method timeouts are enabled and
disabled based on the state of the method checkboxes.

The throttle timeout editbox was poorly aligned.

10 years agoTidy up build directories.
Iain Patterson [Sat, 21 Dec 2013 17:12:10 +0000 (17:12 +0000)]
Tidy up build directories.

Build object files in tmp/<configuration>/<platform> and link
executables in out/<configuration>/<platform>.

Now switching architectures doesn't require a full rebuild and the
working directoryis a bit cleaner.

10 years agoSet service details in the GUI.
Iain Patterson [Sat, 21 Dec 2013 16:10:33 +0000 (16:10 +0000)]
Set service details in the GUI.

The GUI can now set the service display name, description and startup
type.

10 years agoFixed Unicode display of GetProcAddress() errors.
Iain Patterson [Sat, 21 Dec 2013 16:05:18 +0000 (16:05 +0000)]
Fixed Unicode display of GetProcAddress() errors.

GetProcAddress() takes char *name as an argument but we were
trying to print TCHAR *name when logging that we couldn't find the
function pointer.

10 years agoCorrect arguments to GetDlgItemText().
Iain Patterson [Sat, 21 Dec 2013 15:33:23 +0000 (15:33 +0000)]
Correct arguments to GetDlgItemText().

The fourth argument to GetDlgItemText() is a character count not a
buffer size.

10 years agoFixed missing NULLs in log_event().
Iain Patterson [Sat, 21 Dec 2013 12:30:33 +0000 (12:30 +0000)]
Fixed missing NULLs in log_event().

The last argument to log_event must be NULL or messages with too many
parameters may not be logged.

10 years agoFormatting.
Iain Patterson [Sat, 21 Dec 2013 12:29:36 +0000 (12:29 +0000)]
Formatting.

10 years agoRotate output files.
Iain Patterson [Sat, 21 Dec 2013 12:00:53 +0000 (12:00 +0000)]
Rotate output files.

The files specified by AppStdout and AppStderr can now be rotated prior
to launching the application.  An existing file will be renamed with a
new suffix based on its last write time, to millisecond precision.

Rotation is controlled independently of the CreateFile() arguments used
when opening the files for writing.  It is possible to configure
rotation regardless of whether existing files would be appended or
replaced.

Four new REG_DWORD entries control how rotation happens.

If AppRotateFiles is 0 or missing, rotation is disabled.

If AppRotateSeconds is non-zero, a file will not be rotated if its last
write time is less than the given number of seconds in the past.

If AppRotateBytes is non-zero, a file will not be rotated if it is
smaller than the given number of bytes.

64-bit file sizes can be handled by specifying a high order part in
AppRotateBytesHigh.

Thanks Doug Watson.

10 years agoAllow relative paths for I/O redirection.
Iain Patterson [Fri, 20 Dec 2013 19:09:38 +0000 (19:09 +0000)]
Allow relative paths for I/O redirection.

Change to the startup directory before redirecting I/O streams so that
relative paths can be specified.  Then change back so we don't tie up
the directory.

10 years agoVisual Studio notes.
Iain Patterson [Sat, 30 Nov 2013 12:41:24 +0000 (12:41 +0000)]
Visual Studio notes.

Clarify that only Visual Studio 2008 and 2010 are known to work.
Visual Studio 2010 can be used to build executables which run on
Windows versions older than XP SP2 if the platform toolset is set
to v90.

10 years agoUse test_environment().
Iain Patterson [Tue, 26 Nov 2013 17:23:11 +0000 (17:23 +0000)]
Use test_environment().

Use the new test_environment() function when validating the environment
in the GUI and when launching the monitored application fails with
ERROR_INVALID_PARAMETER.  In the latter case we  set service-specific
error code 4 to help identify the reason for the failure.

10 years agoAdded test_environment().
Iain Patterson [Tue, 26 Nov 2013 17:21:27 +0000 (17:21 +0000)]
Added test_environment().

New helper function to verify the environment by relaunching NSSM itself
with the candidate environment set.  Unless something goes horribly
wrong somewhere, CreateProcess() will succeed iff the environment is
valid.

10 years agoDon't try to kill a process which didn't start.
Iain Patterson [Tue, 26 Nov 2013 12:43:06 +0000 (12:43 +0000)]
Don't try to kill a process which didn't start.

If CreateProcess() failed there's no sense trying to call
GetExitCodeProcess() or kill_process_tree().

10 years agoBe less paranoid.
Iain Patterson [Tue, 26 Nov 2013 11:13:42 +0000 (11:13 +0000)]
Be less paranoid.

We were checking that the path to our executable was within MAX_PATH but
it must be by definition and we have been safely skipping the check
elsewhere.

10 years agoBuild NSSM as a Unicode application.
Iain Patterson [Tue, 26 Nov 2013 17:28:02 +0000 (17:28 +0000)]
Build NSSM as a Unicode application.

10 years agoAllow compiling as a Unicode application.
Iain Patterson [Sat, 23 Nov 2013 15:21:54 +0000 (15:21 +0000)]
Allow compiling as a Unicode application.

Overhaul the entire codebase so that it compiles and runs as either a
Unicode or ANSI application.

10 years agoNSSM 2.21. v2.21
Iain Patterson [Sun, 24 Nov 2013 20:37:26 +0000 (20:37 +0000)]
NSSM 2.21.

10 years agoFixed parameters bug when installing from the GUI.
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!"

10 years agoNSSM 2.20. v2.20
Iain Patterson [Sat, 23 Nov 2013 15:44:31 +0000 (15:44 +0000)]
NSSM 2.20.

10 years agoFixed bug when installing from the command line.
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.

10 years agoNSSM 2.19. v2.19
Iain Patterson [Fri, 22 Nov 2013 16:23:53 +0000 (16:23 +0000)]
NSSM 2.19.

10 years agoAllow configuring output file truncation.
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.

10 years agoFixed environment when no newline was present.
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.

10 years agoFix initial focus.
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.

10 years agoEnsure CRLF is removed from GUI strings.
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.

10 years agoCompiler food.
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.

10 years agoSet environment from the GUI at install time.
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.

10 years agoAllow appending to the service environment.
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.

10 years agoGUI overhaul.
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.

10 years agoPass parameters around in a data structure.
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.

10 years agoAdded set_expand_string() and set_number().
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.

10 years agoAdded strip_basename() function.
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.

10 years agoEnforce maximum report delay when starting service.
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.

10 years agoNSSM 2.18. v2.18
Iain Patterson [Fri, 15 Nov 2013 15:59:59 +0000 (15:59 +0000)]
NSSM 2.18.

10 years agoAllow the Escape key to close the GUI.
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.

10 years agoDon't automatically close the GUI on error.
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.

10 years agoSpawn a separate thread for stop_service().
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.

10 years agoUse await_shutdown().
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.

10 years agoAdded await_shutdown() function.
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.

10 years agoPrevent buffer overrun in log_event().
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.

10 years agoAllow overriding time to wait when trying to kill the application.
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.

10 years agoUse override_milliseconds() to find throttle restart delay.
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.

10 years agoAdded override_milliseconds() helper.
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.

10 years agoCalculate service stop wait hint correctly.
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.

10 years agoTypos and formatting etc.
Iain Patterson [Fri, 15 Nov 2013 15:43:46 +0000 (15:43 +0000)]
Typos and formatting etc.

10 years agoNSSM 2.17. v2.17
Iain Patterson [Tue, 12 Nov 2013 12:49:39 +0000 (12:49 +0000)]
NSSM 2.17.

10 years agoFix tabbing between GUI fields.
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.

10 years agoTry to throttle using a critical section.
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.

10 years agoAttachConsole() isn't available in 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.

10 years agoCompiler food.
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.

10 years agoUpdated nssm.dsp with missing dependencies.
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.

10 years agoTry harder not to restart the application when stopping.
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.

10 years agoDelay report that the service is running.
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.

10 years agoSkip some or all methods of stopping the application.
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.

10 years agoFixed Control-C race.
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.

10 years agoRudimentary file versioning.
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.

10 years agoFixed missing io.cpp and io.h.
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.

10 years agoNotes on escaping quotes.
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"""

10 years agoAllow specifying output streams.
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.

10 years agoOverload expand_parameter() like get_number().
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.

10 years agoAdded get_number() helper.
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.

11 years agoTry to send Control-C event to application console.
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.

11 years agoFix build on Visual Studio Express.
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.

11 years agoIgnore INTERROGATE control.
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.

11 years agoNSSM 2.16. v2.16
Iain Patterson [Sun, 2 Dec 2012 05:09:42 +0000 (00:09 -0500)]
NSSM 2.16.

11 years agoFixed crash when stopping the service.
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.

11 years agoNSSM 2.15. v2.15
Iain Patterson [Thu, 19 Jul 2012 20:17:30 +0000 (21:17 +0100)]
NSSM 2.15.

11 years agoItalian translations.
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>
11 years agoFixed buffer length adding a service via the GUI.
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.

11 years agoWhitespace.
Iain Patterson [Thu, 24 May 2012 21:46:07 +0000 (22:46 +0100)]
Whitespace.