Tidy up French GUI.
[nssm.git] / README.txt
1 NSSM: The Non-Sucking Service Manager\r
2 Version 2.24, 2014-08-31\r
3 \r
4 NSSM is a service helper program similar to srvany and cygrunsrv.  It can \r
5 start any application as an NT service and will restart the service if it \r
6 fails for any reason.\r
7 \r
8 NSSM also has a graphical service installer and remover.\r
9 \r
10 Full documentation can be found online at\r
11 \r
12                               http://nssm.cc/\r
13 \r
14 Since version 2.0, the GUI can be bypassed by entering all appropriate \r
15 options on the command line.\r
16 \r
17 Since version 2.1, NSSM can be compiled for x64 platforms.\r
18 Thanks Benjamin Mayrargue.\r
19 \r
20 Since version 2.2, NSSM can be configured to take different actions\r
21 based on the exit code of the managed application.\r
22 \r
23 Since version 2.3, NSSM logs to the Windows event log more elegantly.\r
24 \r
25 Since version 2.5, NSSM respects environment variables in its parameters.\r
26 \r
27 Since version 2.8, NSSM tries harder to shut down the managed application\r
28 gracefully and throttles restart attempts if the application doesn't run\r
29 for a minimum amount of time.\r
30 \r
31 Since version 2.11, NSSM respects srvany's AppEnvironment parameter.\r
32 \r
33 Since version 2.13, NSSM is translated into French.\r
34 Thanks François-Régis Tardy.\r
35 \r
36 Since version 2.15, NSSM is translated into Italian.\r
37 Thanks Riccardo Gusmeroli.\r
38 \r
39 Since version 2.17, NSSM can try to shut down console applications by\r
40 simulating a Control-C keypress.  If they have installed a handler routine\r
41 they can clean up and shut down gracefully on receipt of the event.\r
42 \r
43 Since version 2.17, NSSM can redirect the managed application's I/O streams\r
44 to an arbitrary path.\r
45 \r
46 Since version 2.18, NSSM can be configured to wait a user-specified amount\r
47 of time for the application to exit when shutting down.\r
48 \r
49 Since version 2.19, many more service options can be configured with the\r
50 GUI installer as well as via the registry.\r
51 \r
52 Since version 2.19, NSSM can add to the service's environment by setting\r
53 AppEnvironmentExtra in place of or in addition to the srvany-compatible\r
54 AppEnvironment.\r
55 \r
56 Since version 2.22, NSSM can set the managed application's process priority\r
57 and CPU affinity.\r
58 \r
59 Since version 2.22, NSSM can apply an unconditional delay before restarting\r
60 an application which has exited.\r
61 \r
62 Since version 2.22, NSSM can rotate existing output files when redirecting I/O.\r
63 \r
64 Since version 2.22, NSSM can set service display name, description, startup\r
65 type, log on details and dependencies.\r
66 \r
67 Since version 2.22, NSSM can manage existing services.\r
68 \r
69 Since version 2.25, NSSM can execute commands in response to service events.\r
70 \r
71 Since version 2.25, NSSM can list services it manages.\r
72 \r
73 Since version 2.25, NSSM can dump the configuration of services it manages.\r
74 \r
75 Since version 2.25, NSSM can show the processes managed by a service.\r
76 \r
77 \r
78 Usage\r
79 -----\r
80 In the usage notes below, arguments to the program may be written in angle\r
81 brackets and/or square brackets.  <string> means you must insert the\r
82 appropriate string and [<string>] means the string is optional.  See the\r
83 examples below...\r
84 \r
85 Note that everywhere <servicename> appears you may substitute the\r
86 service's display name.\r
87 \r
88 \r
89 Installation using the GUI\r
90 --------------------------\r
91 To install a service, run\r
92 \r
93     nssm install <servicename>\r
94 \r
95 You will be prompted to enter the full path to the application you wish \r
96 to run and any command line options to pass to that application.\r
97 \r
98 Use the system service manager (services.msc) to control advanced service \r
99 properties such as startup method and desktop interaction.  NSSM may \r
100 support these options at a later time...\r
101 \r
102 \r
103 Installation using the command line\r
104 -----------------------------------\r
105 To install a service, run\r
106 \r
107     nssm install <servicename> <application> [<options>]\r
108 \r
109 NSSM will then attempt to install a service which runs the named application \r
110 with the given options (if you specified any).\r
111 \r
112 Don't forget to enclose paths in "quotes" if they contain spaces!\r
113 \r
114 If you want to include quotes in the options you will need to """quote""" the\r
115 quotes.\r
116 \r
117 \r
118 Managing the service\r
119 --------------------\r
120 NSSM will launch the application listed in the registry when you send it a \r
121 start signal and will terminate it when you send a stop signal.  So far, so \r
122 much like srvany.  But NSSM is the Non-Sucking service manager and can take \r
123 action if/when the application dies.\r
124 \r
125 With no configuration from you, NSSM will try to restart itself if it notices\r
126 that the application died but you didn't send it a stop signal.  NSSM will\r
127 keep trying, pausing between each attempt, until the service is successfully\r
128 started or you send it a stop signal.\r
129 \r
130 NSSM will pause an increasingly longer time between subsequent restart attempts\r
131 if the service fails to start in a timely manner, up to a maximum of four\r
132 minutes.  This is so it does not consume an excessive amount of CPU time trying\r
133 to start a failed application over and over again.  If you identify the cause\r
134 of the failure and don't want to wait you can use the Windows service console\r
135 (where the service will be shown in Paused state) to send a continue signal to\r
136 NSSM and it will retry within a few seconds.\r
137 \r
138 By default, NSSM defines "a timely manner" to be within 1500 milliseconds.\r
139 You can change the threshold for the service by setting the number of\r
140 milliseconds as a REG_DWORD value in the registry at\r
141 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppThrottle.\r
142 \r
143 Alternatively, NSSM can pause for a configurable amount of time before\r
144 attempting to restart the application even if it successfully ran for the\r
145 amount of time specified by AppThrottle.  NSSM will consult the REG_DWORD value\r
146 at HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppRestartDelay\r
147 for the number of milliseconds to wait before attempting a restart.  If\r
148 AppRestartDelay is set and the application is determined to be subject to\r
149 throttling, NSSM will pause the service for whichever is longer of the\r
150 configured restart delay and the calculated throttle period.\r
151 \r
152 If AppRestartDelay is missing or invalid, only throttling will be applied.\r
153 \r
154 NSSM will look in the registry under\r
155 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppExit for\r
156 string (REG_EXPAND_SZ) values corresponding to the exit code of the application.\r
157 If the application exited with code 1, for instance, NSSM will look for a\r
158 string value under AppExit called "1" or, if it does not find it, will\r
159 fall back to the AppExit (Default) value.  You can find out the exit code\r
160 for the application by consulting the system event log.  NSSM will log the\r
161 exit code when the application exits.\r
162 \r
163 Based on the data found in the registry, NSSM will take one of three actions:\r
164 \r
165 If the value data is "Restart" NSSM will try to restart the application as\r
166 described above.  This is its default behaviour.\r
167 \r
168 If the value data is "Ignore" NSSM will not try to restart the application\r
169 but will continue running itself.  This emulates the (usually undesirable)\r
170 behaviour of srvany.  The Windows Services console would show the service\r
171 as still running even though the application has exited.\r
172 \r
173 If the value data is "Exit" NSSM will exit gracefully.  The Windows Services\r
174 console would show the service as stopped.  If you wish to provide\r
175 finer-grained control over service recovery you should use this code and\r
176 edit the failure action manually.  Please note that Windows versions prior\r
177 to Vista will not consider such an exit to be a failure.  On older versions\r
178 of Windows you should use "Suicide" instead.\r
179 \r
180 If the value data is "Suicide" NSSM will simulate a crash and exit without\r
181 informing the service manager.  This option should only be used for\r
182 pre-Vista systems where you wish to apply a service recovery action.  Note\r
183 that if the monitored application exits with code 0, NSSM will only honour a\r
184 request to suicide if you explicitly configure a registry key for exit code 0.\r
185 If only the default action is set to Suicide NSSM will instead exit gracefully.\r
186 \r
187 \r
188 Application priority\r
189 --------------------\r
190 NSSM can set the priority class of the managed application.  NSSM will look in\r
191 the registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\r
192 for the REG_DWORD entry AppPriority.  Valid values correspond to arguments to\r
193 SetPriorityClass().  If AppPriority() is missing or invalid the\r
194 application will be launched with normal priority.\r
195 \r
196 \r
197 Processor affinity\r
198 ------------------\r
199 NSSM can set the CPU affinity of the managed application.  NSSM will look in\r
200 the registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\r
201 for the REG_SZ entry AppAffinity.   It should specify a comma-separated listed\r
202 of zero-indexed processor IDs.  A range of processors may optionally be\r
203 specified with a dash.  No other characters are allowed in the string.\r
204 \r
205 For example, to specify the first; second; third and fifth CPUs, an appropriate\r
206 AppAffinity would be 0-2,4.\r
207 \r
208 If AppAffinity is missing or invalid, NSSM will not attempt to restrict the\r
209 application to specific CPUs.\r
210 \r
211 Note that the 64-bit version of NSSM can configure a maximum of 64 CPUs in this\r
212 way and that the 32-bit version can configure a maxium of 32 CPUs even when\r
213 running on 64-bit Windows.\r
214 \r
215 \r
216 Stopping the service\r
217 --------------------\r
218 When stopping a service NSSM will attempt several different methods of killing\r
219 the monitored application, each of which can be disabled if necessary.\r
220 \r
221 First NSSM will attempt to generate a Control-C event and send it to the\r
222 application's console.  Batch scripts or console applications may intercept\r
223 the event and shut themselves down gracefully.  GUI applications do not have\r
224 consoles and will not respond to this method.\r
225 \r
226 Secondly NSSM will enumerate all windows created by the application and send\r
227 them a WM_CLOSE message, requesting a graceful exit.\r
228 \r
229 Thirdly NSSM will enumerate all threads created by the application and send\r
230 them a WM_QUIT message, requesting a graceful exit.  Not all applications'\r
231 threads have message queues; those which do not will not respond to this\r
232 method.\r
233 \r
234 Finally NSSM will call TerminateProcess() to request that the operating\r
235 system forcibly terminate the application.  TerminateProcess() cannot be\r
236 trapped or ignored, so in most circumstances the application will be killed.\r
237 However, there is no guarantee that it will have a chance to perform any\r
238 tidyup operations before it exits.\r
239 \r
240 Any or all of the methods above may be disabled.  NSSM will look for the\r
241 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppStopMethodSkip\r
242 registry value which should be of type REG_DWORD set to a bit field describing\r
243 which methods should not be applied.\r
244 \r
245   If AppStopMethodSkip includes 1, Control-C events will not be generated.\r
246   If AppStopMethodSkip includes 2, WM_CLOSE messages will not be posted.\r
247   If AppStopMethodSkip includes 4, WM_QUIT messages will not be posted.\r
248   If AppStopMethodSkip includes 8, TerminateProcess() will not be called.\r
249 \r
250 If, for example, you knew that an application did not respond to Control-C\r
251 events and did not have a thread message queue, you could set AppStopMethodSkip\r
252 to 5 and NSSM would not attempt to use those methods to stop the application.\r
253 \r
254 Take great care when including 8 in the value of AppStopMethodSkip.  If NSSM\r
255 does not call TerminateProcess() it is possible that the application will not\r
256 exit when the service stops.\r
257 \r
258 By default NSSM will allow processes 1500ms to respond to each of the methods\r
259 described above before proceeding to the next one.  The timeout can be\r
260 configured on a per-method basis by creating REG_DWORD entries in the\r
261 registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters.\r
262 \r
263   AppStopMethodConsole\r
264   AppStopMethodWindow\r
265   AppStopMethodThreads\r
266 \r
267 Each value should be set to the number of milliseconds to wait.  Please note\r
268 that the timeout applies to each process in the application's process tree,\r
269 so the actual time to shutdown may be longer than the sum of all configured\r
270 timeouts if the application spawns multiple subprocesses.\r
271 \r
272 To skip applying the above stop methods to all processes in the application's\r
273 process tree, applying them only to the original application process, set the\r
274 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppKillProcessTree\r
275 registry value, which should be of type REG_DWORD, to 0.\r
276 \r
277 \r
278 Console window\r
279 --------------\r
280 By default, NSSM will create a console window so that applications which\r
281 are capable of reading user input can do so - subject to the service being\r
282 allowed to interact with the desktop.\r
283 \r
284 Creation of the console can be suppressed by setting the integer (REG_DWORD)\r
285 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppNoConsole\r
286 registry value to 1.\r
287 \r
288 \r
289 I/O redirection\r
290 ---------------\r
291 NSSM can redirect the managed application's I/O to any path capable of being\r
292 opened by CreateFile().  This enables, for example, capturing the log output\r
293 of an application which would otherwise only write to the console or accepting\r
294 input from a serial port.\r
295 \r
296 NSSM will look in the registry under\r
297 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters for the keys\r
298 corresponding to arguments to CreateFile().  All are optional.  If no path is\r
299 given for a particular stream it will not be redirected.  If a path is given\r
300 but any of the other values are omitted they will be receive sensible defaults.\r
301 \r
302   AppStdin: Path to receive input.\r
303   AppStdout: Path to receive output.\r
304   AppStderr: Path to receive error output.\r
305 \r
306 Parameters for CreateFile() are providing with the "AppStdinShareMode",\r
307 "AppStdinCreationDisposition" and "AppStdinFlagsAndAttributes" values (and\r
308 analogously for stdout and stderr).\r
309 \r
310 In general, if you want the service to log its output, set AppStdout and\r
311 AppStderr to the same path, eg C:\Users\Public\service.log, and it should\r
312 work.  Remember, however, that the path must be accessible to the user\r
313 running the service.\r
314 \r
315 \r
316 File rotation\r
317 -------------\r
318 When using I/O redirection, NSSM can rotate existing output files prior to\r
319 opening stdout and/or stderr.  An existing file will be renamed with a\r
320 suffix based on the file's last write time, to millisecond precision.  For\r
321 example, the file nssm.log might be rotated to nssm-20131221T113939.457.log.\r
322 \r
323 NSSM will look in the registry under\r
324 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters for REG_DWORD\r
325 entries which control how rotation happens.\r
326 \r
327 If AppRotateFiles is missing or set to 0, rotation is disabled.  Any non-zero\r
328 value enables rotation.\r
329 \r
330 If AppRotateSeconds is non-zero, a file will not be rotated if its last write\r
331 time is less than the given number of seconds in the past.\r
332 \r
333 If AppRotateBytes is non-zero, a file will not be rotated if it is smaller\r
334 than the given number of bytes.  64-bit file sizes can be handled by setting\r
335 a non-zero value of AppRotateBytesHigh.\r
336 \r
337 If AppRotateDelay is non-zero, NSSM will pause for the given number of\r
338 milliseconds after rotation.\r
339 \r
340 If AppStdoutCopyAndTruncate or AppStderrCopyAndTruncate are non-zero, the\r
341 stdout (or stderr respectively) file will be rotated by first taking a copy\r
342 of the file then truncating the original file to zero size.  This allows\r
343 NSSM to rotate files which are held open by other processes, preventing the\r
344 usual MoveFile() from succeeding.  Note that the copy process may take some\r
345 time if the file is large, and will temporarily consume twice as much disk\r
346 space as the original file.  Note also that applications reading the log file\r
347 may not notice that the file size changed.  Using this option in conjunction\r
348 with AppRotateDelay may help in that case.\r
349 \r
350 Rotation is independent of the CreateFile() parameters used to open the files.\r
351 They will be rotated regardless of whether NSSM would otherwise have appended\r
352 or replaced them.\r
353 \r
354 NSSM can also rotate files which hit the configured size threshold while the\r
355 service is running.  Additionally, you can trigger an on-demand rotation by\r
356 running the command\r
357 \r
358     nssm rotate <servicename>\r
359 \r
360 On-demand rotations will happen after the next line of data is read from\r
361 the managed application, regardless of the value of AppRotateBytes. Be aware\r
362 that if the application is not particularly verbose the rotation may not\r
363 happen for some time.\r
364 \r
365 To enable online and on-demand rotation, set AppRotateOnline to a non-zero\r
366 value.\r
367 \r
368 Note that online rotation requires NSSM to intercept the application's I/O\r
369 and create the output files on its behalf.  This is more complex and\r
370 error-prone than simply redirecting the I/O streams before launching the\r
371 application.  Therefore online rotation is not enabled by default.\r
372 \r
373 \r
374 Timestamping output\r
375 -------------------\r
376 When redirecting output, NSSM can prefix each line of output with a\r
377 millisecond-precision timestamp, for example:\r
378 \r
379     2016-09-06 10:17:09.451 Pipeline main started\r
380 \r
381 To enable timestamp prefixing, set AppTimestampLog to a non-zero value.\r
382 \r
383 The prefix applies to both stdout and stderr.  Prefixing requires\r
384 intercepting the application's I/O in the same way that online rotation\r
385 does.  If log rotation and timestamp prefixing are both enabled, the\r
386 rotation will be online.\r
387 \r
388 \r
389 Environment variables\r
390 ---------------------\r
391 NSSM can replace or append to the managed application's environment.  Two\r
392 multi-valued string (REG_MULTI_SZ) registry values are recognised under\r
393 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters.\r
394 \r
395 AppEnvironment defines a list of environment variables which will override\r
396 the service's environment.  AppEnvironmentExtra defines a list of\r
397 environment variables which will be added to the service's environment.\r
398 \r
399 Each entry in the list should be of the form KEY=VALUE.  It is possible to\r
400 omit the VALUE but the = symbol is mandatory.\r
401 \r
402 Environment variables listed in both AppEnvironment and AppEnvironmentExtra\r
403 are subject to normal expansion, so it is possible, for example, to update the\r
404 system path by setting "PATH=C:\bin;%PATH%" in AppEnvironmentExtra.  Variables\r
405 are expanded in the order in which they appear, so if you want to include the\r
406 value of one variable in another variable you should declare the dependency\r
407 first.\r
408 \r
409 Because variables defined in AppEnvironment override the existing\r
410 environment it is not possible to refer to any variables which were previously\r
411 defined.\r
412 \r
413 For example, the following AppEnvironment block:\r
414 \r
415       PATH=C:\Windows\System32;C:\Windows\r
416       PATH=C:\bin;%PATH%\r
417 \r
418 Would result in a PATH of "C:\bin;C:\Windows\System32;C:\Windows" as expected.\r
419 \r
420 Whereas the following AppEnvironment block:\r
421 \r
422       PATH=C:\bin;%PATH%\r
423 \r
424 Would result in a path containing only C:\bin and probably cause the\r
425 application to fail to start.\r
426 \r
427 Most people will want to use AppEnvironmentExtra exclusively.  srvany only\r
428 supports AppEnvironment.\r
429 \r
430 As of version 2.25, NSSM parses AppEnvironment and AppEnvironmentExtra\r
431 itself, before reading any other registry values.  As a result it is now\r
432 possible to refer to custom environment variables in Application,\r
433 AppDirectory and other parameters.\r
434 \r
435 \r
436 Merged service environment\r
437 --------------------------\r
438 All Windows services can be passed additional environment variables by\r
439 creating a multi-valued string (REG_MULTI_SZ) registry value named\r
440 HLKM\SYSTEM\CurrentControlSet\Services\<service>\Environment.\r
441 \r
442 The contents of this environment block will be merged into the system\r
443 environment before the service starts.\r
444 \r
445 Note, however, that the merged environment will be sorted alphabetically\r
446 before being processed.  This means that in practice you cannot set,\r
447 for example, DIR=%PROGRAMFILES% in the Environment block because the\r
448 environment passed to the service will not have defined %PROGRAMFILES%\r
449 by the time it comes to define %DIR%.  Environment variables defined in\r
450 AppEnvironmentExtra do not suffer from this limitation.\r
451 \r
452 As of version 2.25, NSSM can get and set the Environment block using\r
453 commands similar to:\r
454 \r
455     nssm get <servicename> Environment\r
456 \r
457 It is worth reiterating that the Environment block is available to all\r
458 Windows services, not just NSSM services.\r
459 \r
460 \r
461 Service startup environment\r
462 ---------------------------\r
463 The environment NSSM passes to the application depends on how various\r
464 registry values are configured.  The following flow describes how the\r
465 environment is modified.\r
466 \r
467 By default:\r
468     The service inherits the system environment.\r
469 \r
470 If <service>\Environment is defined:\r
471     The contents of Environment are MERGED into the environment.\r
472 \r
473 If <service>\Parameters\AppEnvironment is defined:\r
474     The service inherits the environment specified in AppEnvironment.\r
475 \r
476 If <service>\Parameters\AppEnvironmentExtra is defined:\r
477     The contents of AppEnvironmentExtra are APPENDED to the environment.\r
478 \r
479 Note that AppEnvironment overrides the system environment and the\r
480 merged Environment block.  Note also that AppEnvironmentExtra is\r
481 guaranteed to be appended to the startup environment if it is defined.\r
482 \r
483 \r
484 Event hooks\r
485 -----------\r
486 NSSM can run user-configurable commands in response to application events.\r
487 These commands are referred to as "hooks" below.\r
488 \r
489 All hooks are optional.  Any hooks which are run will be launched with the\r
490 environment configured for the service.  NSSM will place additional\r
491 variables into the environment which hooks can query to learn how and why\r
492 they were called.\r
493 \r
494 Hooks are categorised by Event and Action.  Some hooks are run synchronously\r
495 and some are run asynchronously.  Hooks prefixed with an *asterisk are run\r
496 synchronously.  NSSM will wait for these hooks to complete before continuing\r
497 its work.  Note, however, that ALL hooks are subject to a deadline after which\r
498 they will be killed, regardless of whether they are run asynchronously\r
499 or not.\r
500 \r
501   Event: Start - Triggered when the service is requested to start.\r
502    *Action: Pre - Called before NSSM attempts to launch the application.\r
503     Action: Post - Called after the application successfully starts.\r
504 \r
505   Event: Stop - Triggered when the service is requested to stop.\r
506    *Action: Pre - Called before NSSM attempts to kill the application.\r
507 \r
508   Event: Exit - Triggered when the application exits.\r
509    *Action: Post - Called after NSSM has cleaned up the application.\r
510 \r
511   Event: Rotate - Triggered when online log rotation is requested.\r
512    *Action: Pre - Called before NSSM rotates logs.\r
513     Action: Post - Called after NSSM rotates logs.\r
514 \r
515   Event: Power\r
516     Action: Change - Called when the system power status has changed.\r
517     Action: Resume - Called when the system has resumed from standby.\r
518 \r
519 Note that there is no Stop/Post hook.  This is because Exit/Post is called\r
520 when the application exits, regardless of whether it did so in response to\r
521 a service shutdown request.  Stop/Pre is only called before a graceful\r
522 shutdown attempt.\r
523 \r
524 NSSM sets the environment variable NSSM_HOOK_VERSION to a positive number.\r
525 Hooks can check the value of the number to determine which other environment\r
526 variables are available to them.\r
527 \r
528 If NSSM_HOOK_VERSION is 1 or greater, these variables are provided:\r
529 \r
530   NSSM_EXE - Path to NSSM itself.\r
531   NSSM_CONFIGURATION - Build information for the NSSM executable,\r
532     eg 64-bit debug.\r
533   NSSM_VERSION - Version of the NSSM executable.\r
534   NSSM_BUILD_DATE - Build date of NSSM.\r
535   NSSM_PID - Process ID of the running NSSM executable.\r
536   NSSM_DEADLINE - Deadline number of milliseconds after which NSSM will\r
537     kill the hook if it is still running.\r
538   NSSM_SERVICE_NAME - Name of the service controlled by NSSM.\r
539   NSSM_SERVICE_DISPLAYNAME - Display name of the service.\r
540   NSSM_COMMAND_LINE - Command line used to launch the application.\r
541   NSSM_APPLICATION_PID - Process ID of the primary application process.\r
542     May be blank if the process is not running.\r
543   NSSM_EVENT - Event class triggering the hook.\r
544   NSSM_ACTION - Event action triggering the hook.\r
545   NSSM_TRIGGER - Service control triggering the hook.  May be blank if\r
546     the hook was not triggered by a service control, eg Exit/Post.\r
547   NSSM_LAST_CONTROL - Last service control handled by NSSM.\r
548   NSSM_START_REQUESTED_COUNT - Number of times the application was\r
549     requested to start.\r
550   NSSM_START_COUNT - Number of times the application successfully started.\r
551   NSSM_THROTTLE_COUNT - Number of times the application ran for less than\r
552     the throttle period.  Reset to zero on successful start or when the\r
553     service is explicitly unpaused.\r
554   NSSM_EXIT_COUNT - Number of times the application exited.\r
555   NSSM_EXITCODE - Exit code of the application.  May be blank if the\r
556     application is still running or has not started yet.\r
557   NSSM_RUNTIME - Number of milliseconds for which the NSSM executable has\r
558     been running.\r
559   NSSM_APPLICATION_RUNTIME - Number of milliseconds for which the\r
560     application has been running since it was last started.  May be blank\r
561     if the application has not been started yet.\r
562 \r
563 Future versions of NSSM may provide more environment variables, in which\r
564 case NSSM_HOOK_VERSION will be set to a higher number.\r
565 \r
566 Hooks are configured by creating string (REG_EXPAND_SZ) values in the\r
567 registry named after the hook action and placed under\r
568 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppEvents\<event>.\r
569 \r
570 For example the service could be configured to restart when the system\r
571 resumes from standby by setting AppEvents\Power\Resume to:\r
572 \r
573     %NSSM_EXE% restart %NSSM_SERVICE_NAME%\r
574 \r
575 To set a hook on the command line, use\r
576 \r
577     nssm set <servicename> AppEvents <event>/<action> <command>\r
578 \r
579 Note that NSSM will abort the startup of the application if a Start/Pre hook\r
580 returns exit code of 99.\r
581 \r
582 A service will normally run hooks in the following order:\r
583 \r
584   Start/Pre\r
585   Start/Post\r
586   Stop/Pre\r
587   Exit/Post\r
588 \r
589 If the application crashes and is restarted by NSSM, the order might be:\r
590 \r
591   Start/Pre\r
592   Start/Post\r
593   Exit/Post\r
594   Start/Pre\r
595   Start/Post\r
596   Stop/Pre\r
597   Exit/Post\r
598 \r
599 \r
600 If NSSM is redirecting stdout or stderr it can be configured to redirect\r
601 the output of any hooks it runs.  Set AppRedirectHooks to 1 to enable\r
602 that functionality.  A hook can of course redirect its own I/O independently\r
603 of NSSM.\r
604 \r
605 \r
606 Managing services using the GUI\r
607 -------------------------------\r
608 NSSM can edit the settings of existing services with the same GUI that is\r
609 used to install them.  Run\r
610 \r
611     nssm edit <servicename>\r
612 \r
613 to bring up the GUI.\r
614 \r
615 NSSM offers limited editing capabilities for services other than those which\r
616 run NSSM itself.  When NSSM is asked to edit a service which does not have\r
617 the App* registry settings described above, the GUI will allow editing only\r
618 system settings such as the service display name and description.\r
619 \r
620 \r
621 Managing services using the command line\r
622 ----------------------------------------\r
623 NSSM can retrieve or set individual service parameters from the command line.\r
624 In general the syntax is as follows, though see below for exceptions.\r
625 \r
626     nssm get <servicename> <parameter>\r
627 \r
628     nssm set <servicename> <parameter> <value>\r
629 \r
630 Parameters can also be reset to their default values.\r
631 \r
632     nssm reset <servicename> <parameter>\r
633 \r
634 The parameter names recognised by NSSM are the same as the registry entry\r
635 names described above, eg AppDirectory.\r
636 \r
637 NSSM offers limited editing capabilities for Services other than those which\r
638 run NSSM itself.  The parameters recognised are as follows:\r
639 \r
640   Description: Service description.\r
641   DisplayName: Service display name.\r
642   Environment: Service merged environment.\r
643   ImagePath: Path to the service executable.\r
644   ObjectName: User account which runs the service.\r
645   Name: Service key name.\r
646   Start: Service startup type.\r
647   Type: Service type.\r
648 \r
649 These correspond to the registry values under the service's key\r
650 HKLM\SYSTEM\CurrentControlSet\Services\<service>.\r
651 \r
652 \r
653 Note that NSSM will concatenate all arguments passed on the command line\r
654 with spaces to form the value to set.  Thus the following two invocations\r
655 would have the same effect.\r
656 \r
657     nssm set <servicename> Description "NSSM managed service"\r
658 \r
659     nssm set <servicename> Description NSSM managed service\r
660 \r
661 \r
662 Non-standard parameters\r
663 -----------------------\r
664 The AppEnvironment, AppEnvironmentExtra and Environment parameters\r
665 recognise an additional argument when querying the environment.  The\r
666 following syntax will print all extra environment variables configured\r
667 for a service\r
668 \r
669     nssm get <servicename> AppEnvironmentExtra\r
670 \r
671 whereas the syntax below will print only the value of the CLASSPATH\r
672 variable if it is configured in the environment block, or the empty string\r
673 if it is not configured.\r
674 \r
675     nssm get <servicename> AppEnvironmentExtra CLASSPATH\r
676 \r
677 When setting an environment block, each variable should be specified as a\r
678 KEY=VALUE pair in separate command line arguments.  For example:\r
679 \r
680     nssm set <servicename> AppEnvironment CLASSPATH=C:\Classes TEMP=C:\Temp\r
681 \r
682 Alternatively the KEY can be prefixed with a + or - symbol to respectively\r
683 add or remove a pair from the block.\r
684 \r
685 The following two lines set CLASSPATH and TEMP:\r
686 \r
687     nssm set <servicename> AppEnvironment CLASSPATH=C:\Classes\r
688     nssm set <servicename> AppEnvironment +TEMP=C:\Temp\r
689 \r
690 If the key is already present, specifying +KEY will override the value\r
691 while preserving the order of keys:\r
692 \r
693     nssm set <servicename> AppEnvironment +CLASSPATH=C:\NewClasses\r
694 \r
695 The following syntax removes a single variable from the block while\r
696 leaving any other variables in place.\r
697 \r
698     nssm set <servicename> AppEnvironment -TEMP\r
699 \r
700 Specifying -KEY=VALUE will remove the variable only if the existing\r
701 value matches.\r
702 \r
703 The following syntax would not remove TEMP=C:\Temp\r
704 \r
705     nssm set <servicename> AppEnvironment -TEMP=C:\Work\Temporary\r
706 \r
707 The + and - symbols are valid characters in environment variables.\r
708 The syntax :KEY=VALUE is equivalent to KEY=VALUE and can be used to\r
709 set variables which start with +/- or to explicitly reset the block in\r
710 a script:\r
711 \r
712     nssm set <servicename> AppEnvironment :CLASSPATH=C:\Classes\r
713     nssm set <servicename> AppEnvironment +TEMP=C:\Temp\r
714 \r
715 \r
716 The AppExit parameter requires an additional argument specifying the exit\r
717 code to get or set.  The default action can be specified with the string\r
718 Default.\r
719 \r
720 For example, to get the default exit action for a service you should run\r
721 \r
722     nssm get <servicename> AppExit Default\r
723 \r
724 To get the exit action when the application exits with exit code 2, run\r
725 \r
726     nssm get <servicename> AppExit 2\r
727 \r
728 Note that if no explicit action is configured for a specified exit code,\r
729 NSSM will print the default exit action.\r
730 \r
731 To set configure the service to stop when the application exits with an\r
732 exit code of 2, run\r
733 \r
734     nssm set <servicename> AppExit 2 Exit\r
735 \r
736 \r
737 The AppPriority parameter is used to set the priority class of the\r
738 managed application.  Valid priorities are as follows:\r
739 \r
740   REALTIME_PRIORITY_CLASS\r
741   HIGH_PRIORITY_CLASS\r
742   ABOVE_NORMAL_PRIORITY_CLASS\r
743   NORMAL_PRIORITY_CLASS\r
744   BELOW_NORMAL_PRIORITY_CLASS\r
745   IDLE_PRIORITY_CLASS\r
746 \r
747 \r
748 The DependOnGroup and DependOnService parameters are used to query or set\r
749 the dependencies for the service.  When setting dependencies, each service\r
750 or service group (preceded with the + symbol) should be specified in\r
751 separate command line arguments.  For example:\r
752 \r
753     nssm set <servicename> DependOnService RpcSs LanmanWorkstation\r
754 \r
755 Alternatively the dependency name can be prefixed with a + or - symbol to\r
756 respectively add or remove a dependency.\r
757 \r
758 The following two lines set dependencies on RpcSs and LanmanWorkstation:\r
759 \r
760     nssm set <servicename> DependOnService RpcSs\r
761     nssm set <servicename> DependOnService +LanmanWorkstation\r
762 \r
763 The follwing syntax removes the dependency on RpcSs:\r
764 \r
765     nssm set <servicename> DependOnService -RpcSs\r
766 \r
767 Service groups should, strictly speaking, be prefixed with the + symbol.\r
768 To specify a single dependency on a group, the + symbol can be prefixed\r
769 with the : symbol.\r
770 \r
771 The following lines are equivalent, and each set a dependency ONLY on\r
772 NetBIOSGroup:\r
773 \r
774     nssm set <servicename> DependOnGroup NetBIOSGroup\r
775     nssm set <servicename> DependOnGroup :NetBIOSGroup\r
776     nssm set <servicename> DependOnGroup :+NetBIOSGroup\r
777 \r
778 Whereas these lines add to any existing dependencies:\r
779 \r
780     nssm set <servicename> DependOnGroup +NetBIOSGroup\r
781     nssm set <servicename> DependOnGroup ++NetBIOSGroup\r
782 \r
783 \r
784 The Name parameter can only be queried, not set.  It returns the service's\r
785 registry key name.  This may be useful to know if you take advantage of\r
786 the fact that you can substitute the service's display name anywhere where\r
787 the syntax calls for <servicename>.\r
788 \r
789 \r
790 The ObjectName parameter requires an additional argument only when setting\r
791 a username.  The additional argument is the password of the user.\r
792 \r
793 To retrieve the username, run\r
794 \r
795     nssm get <servicename> ObjectName\r
796 \r
797 To set the username and password, run\r
798 \r
799     nssm set <servicename> ObjectName <username> <password>\r
800 \r
801 Note that the rules of argument concatenation still apply.  The following\r
802 invocation is valid and will have the expected effect.\r
803 \r
804     nssm set <servicename> ObjectName <username> correct horse battery staple\r
805 \r
806 The following well-known usernames do not need a password.  The password\r
807 parameter can be omitted when using them:\r
808 \r
809   "LocalSystem" aka "System" aka "NT Authority\System"\r
810   "LocalService" aka "Local Service" aka "NT Authority\Local Service"\r
811   "NetworkService" aka "Network Service" aka "NT Authority\Network Service"\r
812   Virtual service account "NT Service\<servicename>"\r
813 \r
814 \r
815 The Start parameter is used to query or set the startup type of the service.\r
816 Valid service startup types are as follows:\r
817 \r
818   SERVICE_AUTO_START: Automatic startup at boot.\r
819   SERVICE_DELAYED_START: Delayed startup at boot.\r
820   SERVICE_DEMAND_START: Manual service startup.\r
821   SERVICE_DISABLED: The service is disabled.\r
822 \r
823 Note that SERVICE_DELAYED_START is not supported on versions of Windows prior\r
824 to Vista.  NSSM will set the service to automatic startup if delayed start is\r
825 unavailable.\r
826 \r
827 \r
828 The Type parameter is used to query or set the service type.  NSSM recognises\r
829 all currently documented service types but will only allow setting one of two\r
830 types:\r
831 \r
832   SERVICE_WIN32_OWN_PROCESS: A standalone service.  This is the default.\r
833   SERVICE_INTERACTIVE_PROCESS: A service which can interact with the desktop.\r
834 \r
835 Note that a service may only be configured as interactive if it runs under\r
836 the LocalSystem account.  The safe way to configure an interactive service\r
837 is in two stages as follows.\r
838 \r
839     nssm reset <servicename> ObjectName\r
840     nssm set <servicename> Type SERVICE_INTERACTIVE_PROCESS\r
841 \r
842 \r
843 Controlling services using the command line\r
844 -------------------------------------------\r
845 NSSM offers rudimentary service control features.\r
846 \r
847     nssm start <servicename>\r
848 \r
849     nssm restart <servicename>\r
850 \r
851     nssm stop <servicename>\r
852 \r
853     nssm status <servicename>\r
854 \r
855     nssm statuscode <servicename>\r
856 \r
857 The output of "nssm status" and "nssm statuscode" is a string\r
858 representing the service state, eg SERVICE_RUNNING.\r
859 \r
860 The exit code of "nssm status" will be 0 if the status was\r
861 succesfully retrieved.  If the exit code is not zero there was\r
862 an error.\r
863 \r
864 The exit code of "nssm statuscode" will be the numeric value\r
865 of the service state, eg 4 for SERVICE_RUNNING.  Zero is not a\r
866 valid service state code.  If the exit code is zero there was\r
867 an error.\r
868 \r
869 \r
870 Removing services using the GUI\r
871 -------------------------------\r
872 NSSM can also remove services.  Run\r
873 \r
874     nssm remove <servicename>\r
875 \r
876 to remove a service.  You will prompted for confirmation before the service \r
877 is removed.  Try not to remove essential system services...\r
878 \r
879 \r
880 Removing service using the command line\r
881 ---------------------------------------\r
882 To remove a service without confirmation from the GUI, run\r
883 \r
884     nssm remove <servicename> confirm\r
885 \r
886 Try not to remove essential system services...\r
887 \r
888 \r
889 Logging\r
890 -------\r
891 NSSM logs to the Windows event log.  It registers itself as an event log source\r
892 and uses unique event IDs for each type of message it logs.  New versions may\r
893 add event types but existing event IDs will never be changed.\r
894 \r
895 Because of the way NSSM registers itself you should be aware that you may not\r
896 be able to replace the NSSM binary if you have the event viewer open and that\r
897 running multiple instances of NSSM from different locations may be confusing if\r
898 they are not all the same version.\r
899 \r
900 \r
901 Listing managed services\r
902 ------------------------\r
903 The following command will print the names of all services managed by NSSM:\r
904 \r
905     nssm list\r
906 \r
907 To see all services on the system, not just NSSM's, use list all:\r
908 \r
909     nssm list all\r
910 \r
911 \r
912 Showing processes started by a service\r
913 --------------------------------------\r
914 The following command will print the process ID and executable path of\r
915 processes started by a given service:\r
916 \r
917     nssm processes <servicename>\r
918 \r
919 Note that if 32-bit NSSM is run on a 64-bit system running an older version of\r
920 Windows than Vista it will not be able to query the paths of 64-bit processes.\r
921 \r
922 \r
923 Exporting service configuration\r
924 -------------------------------\r
925 NSSM can dump commands which would recreate the configuration of a service.\r
926 The output can be pasted into a batch script to back up the service or\r
927 transfer to another computer.\r
928 \r
929     nssm dump <servicename>\r
930 \r
931 Because the service configuration may contain characters which need to be\r
932 quoted or escaped from the command prompt, NSSM tries hard to produce\r
933 output which will work correctly when run as a script, by adding quotes\r
934 and caret escapes as appropriate.\r
935 \r
936 To facilitate copying a service, the dump command accepts a second\r
937 argument which specifies the name of the service to be used in the output.\r
938 \r
939     nssm dump <servicename> <newname>\r
940 \r
941 Lines in the dump will reference the <newname> service while showing the\r
942 configuration of <servicename>.\r
943 \r
944 \r
945 Example usage\r
946 -------------\r
947 To install an Unreal Tournament server:\r
948 \r
949     nssm install UT2004 c:\games\ut2004\system\ucc.exe server\r
950 \r
951 To run the server as the "games" user:\r
952 \r
953     nssm set UT2004 ObjectName games password\r
954 \r
955 To configure the server to log to a file:\r
956 \r
957     nssm set UT2004 AppStdout c:\games\ut2004\service.log\r
958 \r
959 To restrict the server to a single CPU:\r
960 \r
961     nssm set UT2004 AppAffinity 0\r
962 \r
963 To remove the server:\r
964 \r
965     nssm remove UT2004 confirm\r
966 \r
967 To find out the service name of a service with a display name:\r
968 \r
969     nssm get "Background Intelligent Transfer Service" Name\r
970 \r
971 \r
972 Building NSSM from source\r
973 -------------------------\r
974 NSSM is known to compile with Visual Studio 2008 and later.  Older Visual\r
975 Studio releases may or may not work if you install an appropriate SDK and\r
976 edit the nssm.vcproj and nssm.sln files to set a lower version number.\r
977 They are known not to work with default settings.\r
978 \r
979 NSSM will also compile with Visual Studio 2010 but the resulting executable\r
980 will not run on versions of Windows older than XP SP2.  If you require\r
981 compatiblity with older Windows releases you should change the Platform\r
982 Toolset to v90 in the General section of the project's Configuration\r
983 Properties.\r
984 \r
985 \r
986 Credits\r
987 -------\r
988 Thanks to Bernard Loh for finding a bug with service recovery.\r
989 Thanks to Benjamin Mayrargue (www.softlion.com) for adding 64-bit support.\r
990 Thanks to Joel Reingold for spotting a command line truncation bug.\r
991 Thanks to Arve Knudsen for spotting that child processes of the monitored\r
992 application could be left running on service shutdown, and that a missing\r
993 registry value for AppDirectory confused NSSM.\r
994 Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling\r
995 restarts.\r
996 Thanks to Eugene Lifshitz for finding an edge case in CreateProcess() and for\r
997 advising how to build messages.mc correctly in paths containing spaces.\r
998 Thanks to Rob Sharp for pointing out that NSSM did not respect the\r
999 AppEnvironment registry value used by srvany.\r
1000 Thanks to Szymon Nowak for help with Windows 2000 compatibility.\r
1001 Thanks to François-Régis Tardy and Gildas le Nadan for French translation.\r
1002 Thanks to Emilio Frini for spotting that French was inadvertently set as\r
1003 the default language when the user's display language was not translated.\r
1004 Thanks to Riccardo Gusmeroli and Marco Certelli for Italian translation.\r
1005 Thanks to Eric Cheldelin for the inspiration to generate a Control-C event\r
1006 on shutdown.\r
1007 Thanks to Brian Baxter for suggesting how to escape quotes from the command\r
1008 prompt.\r
1009 Thanks to Russ Holmann for suggesting that the shutdown timeout be configurable.\r
1010 Thanks to Paul Spause for spotting a bug with default registry entries.\r
1011 Thanks to BUGHUNTER for spotting more GUI bugs.\r
1012 Thanks to Doug Watson for suggesting file rotation.\r
1013 Thanks to Арслан Сайдуганов for suggesting setting process priority.\r
1014 Thanks to Robert Middleton for suggestion and draft implementation of process\r
1015 affinity support.\r
1016 Thanks to Andrew RedzMax for suggesting an unconditional restart delay.\r
1017 Thanks to Bryan Senseman for noticing that applications with redirected stdout\r
1018 and/or stderr which attempt to read from stdin would fail.\r
1019 Thanks to Czenda Czendov for help with Visual Studio 2013 and Server 2012R2.\r
1020 Thanks to Alessandro Gherardi for reporting and draft fix of the bug whereby\r
1021 the second restart of the application would have a corrupted environment.\r
1022 Thanks to Hadrien Kohl for suggesting to disable the console window's menu.\r
1023 Thanks to Allen Vailliencourt for noticing bugs with configuring the service to\r
1024 run under a local user account.\r
1025 Thanks to Sam Townsend for noticing a regression with TerminateProcess().\r
1026 Thanks to Barrett Lewis for suggesting the option to skip terminating the\r
1027 application's child processes.\r
1028 Thanks to Miguel Angel Terrón for suggesting copy/truncate rotation.\r
1029 Thanks to Yuriy Lesiuk for suggesting setting the environment before querying\r
1030 the registry for parameters.\r
1031 Thanks to Gerald Haider for noticing that installing a service with NSSM in a\r
1032 path containing spaces was technically a security vulnerability.\r
1033 Thanks to Scott Ware for reporting a crash saving the environment on XP 32-bit.\r
1034 Thanks to Stefan and Michael Scherer for reporting a bug writing the event messages source.\r
1035 Thanks to Paul Baxter for help with Visual Studio 2015.\r
1036 Thanks to Mathias Breiner for help with Visual Studio and some registry fixes.\r
1037 Thanks to David Bremner for general tidyups.\r
1038 Thanks to Nabil Redmann for suggesting redirecting hooks' output.\r
1039 Thanks to Bader Aldurai for suggesting the process tree.\r
1040 Thanks to Christian Long for suggesting virtual accounts.\r
1041 Thanks to Marcin Lewandowski for spotting a bug appending to large files.\r
1042 Thanks to Nicolas Ducrocq for suggesting timestamping redirected output.\r
1043 Thanks to Meang Akira Tanaka for suggestion and initial implementation of\r
1044 the statuscode command.\r
1045 \r
1046 Licence\r
1047 -------\r
1048 NSSM is public domain.  You may unconditionally use it and/or its source code \r
1049 for any purpose you wish.\r