README.txt 36 KB

  1. NSSM: The Non-Sucking Service Manager
  2. Version 2.24, 2014-08-31
  3. NSSM is a service helper program similar to srvany and cygrunsrv. It can
  4. start any application as an NT service and will restart the service if it
  5. fails for any reason.
  6. NSSM also has a graphical service installer and remover.
  7. Full documentation can be found online at
  9. Since version 2.0, the GUI can be bypassed by entering all appropriate
  10. options on the command line.
  11. Since version 2.1, NSSM can be compiled for x64 platforms.
  12. Thanks Benjamin Mayrargue.
  13. Since version 2.2, NSSM can be configured to take different actions
  14. based on the exit code of the managed application.
  15. Since version 2.3, NSSM logs to the Windows event log more elegantly.
  16. Since version 2.5, NSSM respects environment variables in its parameters.
  17. Since version 2.8, NSSM tries harder to shut down the managed application
  18. gracefully and throttles restart attempts if the application doesn't run
  19. for a minimum amount of time.
  20. Since version 2.11, NSSM respects srvany's AppEnvironment parameter.
  21. Since version 2.13, NSSM is translated into French.
  22. Thanks François-Régis Tardy.
  23. Since version 2.15, NSSM is translated into Italian.
  24. Thanks Riccardo Gusmeroli.
  25. Since version 2.17, NSSM can try to shut down console applications by
  26. simulating a Control-C keypress. If they have installed a handler routine
  27. they can clean up and shut down gracefully on receipt of the event.
  28. Since version 2.17, NSSM can redirect the managed application's I/O streams
  29. to an arbitrary path.
  30. Since version 2.18, NSSM can be configured to wait a user-specified amount
  31. of time for the application to exit when shutting down.
  32. Since version 2.19, many more service options can be configured with the
  33. GUI installer as well as via the registry.
  34. Since version 2.19, NSSM can add to the service's environment by setting
  35. AppEnvironmentExtra in place of or in addition to the srvany-compatible
  36. AppEnvironment.
  37. Since version 2.22, NSSM can set the managed application's process priority
  38. and CPU affinity.
  39. Since version 2.22, NSSM can apply an unconditional delay before restarting
  40. an application which has exited.
  41. Since version 2.22, NSSM can rotate existing output files when redirecting I/O.
  42. Since version 2.22, NSSM can set service display name, description, startup
  43. type, log on details and dependencies.
  44. Since version 2.22, NSSM can manage existing services.
  45. Since version 2.25, NSSM can execute commands in response to service events.
  46. Usage
  47. -----
  48. In the usage notes below, arguments to the program may be written in angle
  49. brackets and/or square brackets. <string> means you must insert the
  50. appropriate string and [<string>] means the string is optional. See the
  51. examples below...
  52. Note that everywhere <servicename> appears you may substitute the
  53. service's display name.
  54. Installation using the GUI
  55. --------------------------
  56. To install a service, run
  57. nssm install <servicename>
  58. You will be prompted to enter the full path to the application you wish
  59. to run and any command line options to pass to that application.
  60. Use the system service manager (services.msc) to control advanced service
  61. properties such as startup method and desktop interaction. NSSM may
  62. support these options at a later time...
  63. Installation using the command line
  64. -----------------------------------
  65. To install a service, run
  66. nssm install <servicename> <application> [<options>]
  67. NSSM will then attempt to install a service which runs the named application
  68. with the given options (if you specified any).
  69. Don't forget to enclose paths in "quotes" if they contain spaces!
  70. If you want to include quotes in the options you will need to """quote""" the
  72. Managing the service
  73. --------------------
  74. NSSM will launch the application listed in the registry when you send it a
  75. start signal and will terminate it when you send a stop signal. So far, so
  76. much like srvany. But NSSM is the Non-Sucking service manager and can take
  77. action if/when the application dies.
  78. With no configuration from you, NSSM will try to restart itself if it notices
  79. that the application died but you didn't send it a stop signal. NSSM will
  80. keep trying, pausing between each attempt, until the service is successfully
  81. started or you send it a stop signal.
  82. NSSM will pause an increasingly longer time between subsequent restart attempts
  83. if the service fails to start in a timely manner, up to a maximum of four
  84. minutes. This is so it does not consume an excessive amount of CPU time trying
  85. to start a failed application over and over again. If you identify the cause
  86. of the failure and don't want to wait you can use the Windows service console
  87. (where the service will be shown in Paused state) to send a continue signal to
  88. NSSM and it will retry within a few seconds.
  89. By default, NSSM defines "a timely manner" to be within 1500 milliseconds.
  90. You can change the threshold for the service by setting the number of
  91. milliseconds as a REG_DWORD value in the registry at
  92. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppThrottle.
  93. Alternatively, NSSM can pause for a configurable amount of time before
  94. attempting to restart the application even if it successfully ran for the
  95. amount of time specified by AppThrottle. NSSM will consult the REG_DWORD value
  96. at HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppRestartDelay
  97. for the number of milliseconds to wait before attempting a restart. If
  98. AppRestartDelay is set and the application is determined to be subject to
  99. throttling, NSSM will pause the service for whichever is longer of the
  100. configured restart delay and the calculated throttle period.
  101. If AppRestartDelay is missing or invalid, only throttling will be applied.
  102. NSSM will look in the registry under
  103. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppExit for
  104. string (REG_EXPAND_SZ) values corresponding to the exit code of the application.
  105. If the application exited with code 1, for instance, NSSM will look for a
  106. string value under AppExit called "1" or, if it does not find it, will
  107. fall back to the AppExit (Default) value. You can find out the exit code
  108. for the application by consulting the system event log. NSSM will log the
  109. exit code when the application exits.
  110. Based on the data found in the registry, NSSM will take one of three actions:
  111. If the value data is "Restart" NSSM will try to restart the application as
  112. described above. This is its default behaviour.
  113. If the value data is "Ignore" NSSM will not try to restart the application
  114. but will continue running itself. This emulates the (usually undesirable)
  115. behaviour of srvany. The Windows Services console would show the service
  116. as still running even though the application has exited.
  117. If the value data is "Exit" NSSM will exit gracefully. The Windows Services
  118. console would show the service as stopped. If you wish to provide
  119. finer-grained control over service recovery you should use this code and
  120. edit the failure action manually. Please note that Windows versions prior
  121. to Vista will not consider such an exit to be a failure. On older versions
  122. of Windows you should use "Suicide" instead.
  123. If the value data is "Suicide" NSSM will simulate a crash and exit without
  124. informing the service manager. This option should only be used for
  125. pre-Vista systems where you wish to apply a service recovery action. Note
  126. that if the monitored application exits with code 0, NSSM will only honour a
  127. request to suicide if you explicitly configure a registry key for exit code 0.
  128. If only the default action is set to Suicide NSSM will instead exit gracefully.
  129. Application priority
  130. --------------------
  131. NSSM can set the priority class of the managed application. NSSM will look in
  132. the registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters
  133. for the REG_DWORD entry AppPriority. Valid values correspond to arguments to
  134. SetPriorityClass(). If AppPriority() is missing or invalid the
  135. application will be launched with normal priority.
  136. Processor affinity
  137. ------------------
  138. NSSM can set the CPU affinity of the managed application. NSSM will look in
  139. the registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters
  140. for the REG_SZ entry AppAffinity. It should specify a comma-separated listed
  141. of zero-indexed processor IDs. A range of processors may optionally be
  142. specified with a dash. No other characters are allowed in the string.
  143. For example, to specify the first; second; third and fifth CPUs, an appropriate
  144. AppAffinity would be 0-2,4.
  145. If AppAffinity is missing or invalid, NSSM will not attempt to restrict the
  146. application to specific CPUs.
  147. Note that the 64-bit version of NSSM can configure a maximum of 64 CPUs in this
  148. way and that the 32-bit version can configure a maxium of 32 CPUs even when
  149. running on 64-bit Windows.
  150. Stopping the service
  151. --------------------
  152. When stopping a service NSSM will attempt several different methods of killing
  153. the monitored application, each of which can be disabled if necessary.
  154. First NSSM will attempt to generate a Control-C event and send it to the
  155. application's console. Batch scripts or console applications may intercept
  156. the event and shut themselves down gracefully. GUI applications do not have
  157. consoles and will not respond to this method.
  158. Secondly NSSM will enumerate all windows created by the application and send
  159. them a WM_CLOSE message, requesting a graceful exit.
  160. Thirdly NSSM will enumerate all threads created by the application and send
  161. them a WM_QUIT message, requesting a graceful exit. Not all applications'
  162. threads have message queues; those which do not will not respond to this
  163. method.
  164. Finally NSSM will call TerminateProcess() to request that the operating
  165. system forcibly terminate the application. TerminateProcess() cannot be
  166. trapped or ignored, so in most circumstances the application will be killed.
  167. However, there is no guarantee that it will have a chance to perform any
  168. tidyup operations before it exits.
  169. Any or all of the methods above may be disabled. NSSM will look for the
  170. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppStopMethodSkip
  171. registry value which should be of type REG_DWORD set to a bit field describing
  172. which methods should not be applied.
  173. If AppStopMethodSkip includes 1, Control-C events will not be generated.
  174. If AppStopMethodSkip includes 2, WM_CLOSE messages will not be posted.
  175. If AppStopMethodSkip includes 4, WM_QUIT messages will not be posted.
  176. If AppStopMethodSkip includes 8, TerminateProcess() will not be called.
  177. If, for example, you knew that an application did not respond to Control-C
  178. events and did not have a thread message queue, you could set AppStopMethodSkip
  179. to 5 and NSSM would not attempt to use those methods to stop the application.
  180. Take great care when including 8 in the value of AppStopMethodSkip. If NSSM
  181. does not call TerminateProcess() it is possible that the application will not
  182. exit when the service stops.
  183. By default NSSM will allow processes 1500ms to respond to each of the methods
  184. described above before proceeding to the next one. The timeout can be
  185. configured on a per-method basis by creating REG_DWORD entries in the
  186. registry under HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters.
  187. AppStopMethodConsole
  188. AppStopMethodWindow
  189. AppStopMethodThreads
  190. Each value should be set to the number of milliseconds to wait. Please note
  191. that the timeout applies to each process in the application's process tree,
  192. so the actual time to shutdown may be longer than the sum of all configured
  193. timeouts if the application spawns multiple subprocesses.
  194. To skip applying the above stop methods to all processes in the application's
  195. process tree, applying them only to the original application process, set the
  196. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppKillProcessTree
  197. registry value, which should be of type REG_DWORD, to 0.
  198. Console window
  199. --------------
  200. By default, NSSM will create a console window so that applications which
  201. are capable of reading user input can do so - subject to the service being
  202. allowed to interact with the desktop.
  203. Creation of the console can be suppressed by setting the integer (REG_DWORD)
  204. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppNoConsole
  205. registry value to 1.
  206. I/O redirection
  207. ---------------
  208. NSSM can redirect the managed application's I/O to any path capable of being
  209. opened by CreateFile(). This enables, for example, capturing the log output
  210. of an application which would otherwise only write to the console or accepting
  211. input from a serial port.
  212. NSSM will look in the registry under
  213. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters for the keys
  214. corresponding to arguments to CreateFile(). All are optional. If no path is
  215. given for a particular stream it will not be redirected. If a path is given
  216. but any of the other values are omitted they will be receive sensible defaults.
  217. AppStdin: Path to receive input.
  218. AppStdout: Path to receive output.
  219. AppStderr: Path to receive error output.
  220. Parameters for CreateFile() are providing with the "AppStdinShareMode",
  221. "AppStdinCreationDisposition" and "AppStdinFlagsAndAttributes" values (and
  222. analogously for stdout and stderr).
  223. In general, if you want the service to log its output, set AppStdout and
  224. AppStderr to the same path, eg C:\Users\Public\service.log, and it should
  225. work. Remember, however, that the path must be accessible to the user
  226. running the service.
  227. File rotation
  228. -------------
  229. When using I/O redirection, NSSM can rotate existing output files prior to
  230. opening stdout and/or stderr. An existing file will be renamed with a
  231. suffix based on the file's last write time, to millisecond precision. For
  232. example, the file nssm.log might be rotated to nssm-20131221T113939.457.log.
  233. NSSM will look in the registry under
  234. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters for REG_DWORD
  235. entries which control how rotation happens.
  236. If AppRotateFiles is missing or set to 0, rotation is disabled. Any non-zero
  237. value enables rotation.
  238. If AppRotateSeconds is non-zero, a file will not be rotated if its last write
  239. time is less than the given number of seconds in the past.
  240. If AppRotateBytes is non-zero, a file will not be rotated if it is smaller
  241. than the given number of bytes. 64-bit file sizes can be handled by setting
  242. a non-zero value of AppRotateBytesHigh.
  243. If AppRotateDelay is non-zero, NSSM will pause for the given number of
  244. milliseconds after rotation.
  245. If AppStdoutCopyAndTruncate or AppStderrCopyAndTruncate are non-zero, the
  246. stdout (or stderr respectively) file will be rotated by first taking a copy
  247. of the file then truncating the original file to zero size. This allows
  248. NSSM to rotate files which are held open by other processes, preventing the
  249. usual MoveFile() from succeeding. Note that the copy process may take some
  250. time if the file is large, and will temporarily consume twice as much disk
  251. space as the original file. Note also that applications reading the log file
  252. may not notice that the file size changed. Using this option in conjunction
  253. with AppRotateDelay may help in that case.
  254. Rotation is independent of the CreateFile() parameters used to open the files.
  255. They will be rotated regardless of whether NSSM would otherwise have appended
  256. or replaced them.
  257. NSSM can also rotate files which hit the configured size threshold while the
  258. service is running. Additionally, you can trigger an on-demand rotation by
  259. running the command
  260. nssm rotate <servicename>
  261. On-demand rotations will happen after the next line of data is read from
  262. the managed application, regardless of the value of AppRotateBytes. Be aware
  263. that if the application is not particularly verbose the rotation may not
  264. happen for some time.
  265. To enable online and on-demand rotation, set AppRotateOnline to a non-zero
  266. value.
  267. Note that online rotation requires NSSM to intercept the application's I/O
  268. and create the output files on its behalf. This is more complex and
  269. error-prone than simply redirecting the I/O streams before launching the
  270. application. Therefore online rotation is not enabled by default.
  271. Environment variables
  272. ---------------------
  273. NSSM can replace or append to the managed application's environment. Two
  274. multi-valued string (REG_MULTI_SZ) registry values are recognised under
  275. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters.
  276. AppEnvironment defines a list of environment variables which will override
  277. the service's environment. AppEnvironmentExtra defines a list of
  278. environment variables which will be added to the service's environment.
  279. Each entry in the list should be of the form KEY=VALUE. It is possible to
  280. omit the VALUE but the = symbol is mandatory.
  281. Environment variables listed in both AppEnvironment and AppEnvironmentExtra
  282. are subject to normal expansion, so it is possible, for example, to update the
  283. system path by setting "PATH=C:\bin;%PATH%" in AppEnvironmentExtra. Variables
  284. are expanded in the order in which they appear, so if you want to include the
  285. value of one variable in another variable you should declare the dependency
  286. first.
  287. Because variables defined in AppEnvironment override the existing
  288. environment it is not possible to refer to any variables which were previously
  289. defined.
  290. For example, the following AppEnvironment block:
  291. PATH=C:\Windows\System32;C:\Windows
  292. PATH=C:\bin;%PATH%
  293. Would result in a PATH of "C:\bin;C:\Windows\System32;C:\Windows" as expected.
  294. Whereas the following AppEnvironment block:
  295. PATH=C:\bin;%PATH%
  296. Would result in a path containing only C:\bin and probably cause the
  297. application to fail to start.
  298. Most people will want to use AppEnvironmentExtra exclusively. srvany only
  299. supports AppEnvironment.
  300. As of version 2.25, NSSM parses AppEnvironment and AppEnvironmentExtra
  301. itself, before reading any other registry values. As a result it is now
  302. possible to refer to custom environment variables in Application,
  303. AppDirectory and other parameters.
  304. Merged service environment
  305. --------------------------
  306. All Windows services can be passed additional environment variables by
  307. creating a multi-valued string (REG_MULTI_SZ) registry value named
  308. HLKM\SYSTEM\CurrentControlSet\Services\<service>\Environment.
  309. The contents of this environment block will be merged into the system
  310. environment before the service starts.
  311. Note, however, that the merged environment will be sorted alphabetically
  312. before being processed. This means that in practice you cannot set,
  313. for example, DIR=%PROGRAMFILES% in the Environment block because the
  314. environment passed to the service will not have defined %PROGRAMFILES%
  315. by the time it comes to define %DIR%. Environment variables defined in
  316. AppEnvironmentExtra do not suffer from this limitation.
  317. As of version 2.25, NSSM can get and set the Environment block using
  318. commands similar to:
  319. nssm get <servicename> Environment
  320. It is worth reiterating that the Environment block is available to all
  321. Windows services, not just NSSM services.
  322. Service startup environment
  323. ---------------------------
  324. The environment NSSM passes to the application depends on how various
  325. registry values are configured. The following flow describes how the
  326. environment is modified.
  327. By default:
  328. The service inherits the system environment.
  329. If <service>\Environment is defined:
  330. The contents of Environment are MERGED into the environment.
  331. If <service>\Parameters\AppEnvironment is defined:
  332. The service inherits the environment specified in AppEnvironment.
  333. If <service>\Parameters\AppEnvironmentExtra is defined:
  334. The contents of AppEnvironmentExtra are APPENDED to the environment.
  335. Note that AppEnvironment overrides the system environment and the
  336. merged Environment block. Note also that AppEnvironmentExtra is
  337. guaranteed to be appended to the startup environment if it is defined.
  338. Event hooks
  339. -----------
  340. NSSM can run user-configurable commands in response to application events.
  341. These commands are referred to as "hooks" below.
  342. All hooks are optional. Any hooks which are run will be launched with the
  343. environment configured for the service. NSSM will place additional
  344. variables into the environment which hooks can query to learn how and why
  345. they were called.
  346. Hooks are categorised by Event and Action. Some hooks are run synchronously
  347. and some are run asynchronously. Hooks prefixed with an *asterisk are run
  348. synchronously. NSSM will wait for these hooks to complete before continuing
  349. its work. Note, however, that ALL hooks are subject to a deadline after which
  350. they will be killed, regardless of whether they are run asynchronously
  351. or not.
  352. Event: Start - Triggered when the service is requested to start.
  353. *Action: Pre - Called before NSSM attempts to launch the application.
  354. Action: Post - Called after the application successfully starts.
  355. Event: Stop - Triggered when the service is requested to stop.
  356. *Action: Pre - Called before NSSM attempts to kill the application.
  357. Event: Exit - Triggered when the application exits.
  358. *Action: Post - Called after NSSM has cleaned up the application.
  359. Event: Rotate - Triggered when online log rotation is requested.
  360. *Action: Pre - Called before NSSM rotates logs.
  361. Action: Post - Called after NSSM rotates logs.
  362. Event: Power
  363. Action: Change - Called when the system power status has changed.
  364. Action: Resume - Called when the system has resumed from standby.
  365. Note that there is no Stop/Post hook. This is because Exit/Post is called
  366. when the application exits, regardless of whether it did so in response to
  367. a service shutdown request. Stop/Pre is only called before a graceful
  368. shutdown attempt.
  369. NSSM sets the environment variable NSSM_HOOK_VERSION to a positive number.
  370. Hooks can check the value of the number to determine which other environment
  371. variables are available to them.
  372. If NSSM_HOOK_VERSION is 1 or greater, these variables are provided:
  373. NSSM_EXE - Path to NSSM itself.
  374. NSSM_CONFIGURATION - Build information for the NSSM executable,
  375. eg 64-bit debug.
  376. NSSM_VERSION - Version of the NSSM executable.
  377. NSSM_BUILD_DATE - Build date of NSSM.
  378. NSSM_PID - Process ID of the running NSSM executable.
  379. NSSM_DEADLINE - Deadline number of milliseconds after which NSSM will
  380. kill the hook if it is still running.
  381. NSSM_SERVICE_NAME - Name of the service controlled by NSSM.
  382. NSSM_SERVICE_DISPLAYNAME - Display name of the service.
  383. NSSM_COMMAND_LINE - Command line used to launch the application.
  384. NSSM_APPLICATION_PID - Process ID of the primary application process.
  385. May be blank if the process is not running.
  386. NSSM_EVENT - Event class triggering the hook.
  387. NSSM_ACTION - Event action triggering the hook.
  388. NSSM_TRIGGER - Service control triggering the hook. May be blank if
  389. the hook was not triggered by a service control, eg Exit/Post.
  390. NSSM_LAST_CONTROL - Last service control handled by NSSM.
  391. NSSM_START_REQUESTED_COUNT - Number of times the application was
  392. requested to start.
  393. NSSM_START_COUNT - Number of times the application successfully started.
  394. NSSM_THROTTLE_COUNT - Number of times the application ran for less than
  395. the throttle period. Reset to zero on successful start or when the
  396. service is explicitly unpaused.
  397. NSSM_EXIT_COUNT - Number of times the application exited.
  398. NSSM_EXITCODE - Exit code of the application. May be blank if the
  399. application is still running or has not started yet.
  400. NSSM_RUNTIME - Number of milliseconds for which the NSSM executable has
  401. been running.
  402. NSSM_APPLICATION_RUNTIME - Number of milliseconds for which the
  403. application has been running since it was last started. May be blank
  404. if the application has not been started yet.
  405. Future versions of NSSM may provide more environment variables, in which
  406. case NSSM_HOOK_VERSION will be set to a higher number.
  407. Hooks are configured by creating string (REG_EXPAND_SZ) values in the
  408. registry named after the hook action and placed under
  409. HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppEvents\<event>.
  410. For example the service could be configured to restart when the system
  411. resumes from standby by setting AppEvents\Power\Resume to:
  412. %NSSM_EXE% restart %NSSM_SERVICE_NAME%
  413. Note that NSSM will abort the startup of the application if a Start/Pre hook
  414. returns exit code of 99.
  415. A service will normally run hooks in the following order:
  416. Start/Pre
  417. Start/Post
  418. Stop/Pre
  419. Exit/Post
  420. If the application crashes and is restarted by NSSM, the order might be:
  421. Start/Pre
  422. Start/Post
  423. Exit/Post
  424. Start/Pre
  425. Start/Post
  426. Stop/Pre
  427. Exit/Post
  428. Managing services using the GUI
  429. -------------------------------
  430. NSSM can edit the settings of existing services with the same GUI that is
  431. used to install them. Run
  432. nssm edit <servicename>
  433. to bring up the GUI.
  434. NSSM offers limited editing capabilities for services other than those which
  435. run NSSM itself. When NSSM is asked to edit a service which does not have
  436. the App* registry settings described above, the GUI will allow editing only
  437. system settings such as the service display name and description.
  438. Managing services using the command line
  439. ----------------------------------------
  440. NSSM can retrieve or set individual service parameters from the command line.
  441. In general the syntax is as follows, though see below for exceptions.
  442. nssm get <servicename> <parameter>
  443. nssm set <servicename> <parameter> <value>
  444. Parameters can also be reset to their default values.
  445. nssm reset <servicename> <parameter>
  446. The parameter names recognised by NSSM are the same as the registry entry
  447. names described above, eg AppDirectory.
  448. NSSM offers limited editing capabilities for Services other than those which
  449. run NSSM itself. The parameters recognised are as follows:
  450. Description: Service description.
  451. DisplayName: Service display name.
  452. Environment: Service merged environment.
  453. ImagePath: Path to the service executable.
  454. ObjectName: User account which runs the service.
  455. Name: Service key name.
  456. Start: Service startup type.
  457. Type: Service type.
  458. These correspond to the registry values under the service's key
  459. HKLM\SYSTEM\CurrentControlSet\Services\<service>.
  460. Note that NSSM will concatenate all arguments passed on the command line
  461. with spaces to form the value to set. Thus the following two invocations
  462. would have the same effect.
  463. nssm set <servicename> Description "NSSM managed service"
  464. nssm set <servicename> Description NSSM managed service
  465. Non-standard parameters
  466. -----------------------
  467. The AppEnvironment and AppEnvironmentExtra parameters recognise an
  468. additional argument when querying the environment. The following syntax
  469. will print all extra environment variables configured for a service
  470. nssm get <servicename> AppEnvironmentExtra
  471. whereas the syntax below will print only the value of the CLASSPATH
  472. variable if it is configured in the environment block, or the empty string
  473. if it is not configured.
  474. nssm get <servicename> AppEnvironmentExtra CLASSPATH
  475. When setting an environment block, each variable should be specified as a
  476. KEY=VALUE pair in separate command line arguments. For example:
  477. nssm set <servicename> AppEnvironment CLASSPATH=C:\Classes TEMP=C:\Temp
  478. The AppExit parameter requires an additional argument specifying the exit
  479. code to get or set. The default action can be specified with the string
  480. Default.
  481. For example, to get the default exit action for a service you should run
  482. nssm get <servicename> AppExit Default
  483. To get the exit action when the application exits with exit code 2, run
  484. nssm get <servicename> AppExit 2
  485. Note that if no explicit action is configured for a specified exit code,
  486. NSSM will print the default exit action.
  487. To set configure the service to stop when the application exits with an
  488. exit code of 2, run
  489. nssm set <servicename> AppExit 2 Exit
  490. The AppPriority parameter is used to set the priority class of the
  491. managed application. Valid priorities are as follows:
  498. The DependOnGroup and DependOnService parameters are used to query or set
  499. the dependencies for the service. When setting dependencies, each service
  500. or service group (preceded with the + symbol) should be specified in
  501. separate command line arguments. For example:
  502. nssm set <servicename> DependOnService RpcSs LanmanWorkstation
  503. The Name parameter can only be queried, not set. It returns the service's
  504. registry key name. This may be useful to know if you take advantage of
  505. the fact that you can substitute the service's display name anywhere where
  506. the syntax calls for <servicename>.
  507. The ObjectName parameter requires an additional argument only when setting
  508. a username. The additional argument is the password of the user.
  509. To retrieve the username, run
  510. nssm get <servicename> ObjectName
  511. To set the username and password, run
  512. nssm set <servicename> ObjectName <username> <password>
  513. Note that the rules of argument concatenation still apply. The following
  514. invocation is valid and will have the expected effect.
  515. nssm set <servicename> ObjectName <username> correct horse battery staple
  516. The following well-known usernames do not need a password. The password
  517. parameter can be omitted when using them:
  518. "LocalSystem" aka "System" aka "NT Authority\System"
  519. "LocalService" aka "Local Service" aka "NT Authority\Local Service"
  520. "NetworkService" aka "Network Service" aka "NT Authority\Network Service"
  521. The Start parameter is used to query or set the startup type of the service.
  522. Valid service startup types are as follows:
  523. SERVICE_AUTO_START: Automatic startup at boot.
  524. SERVICE_DELAYED_START: Delayed startup at boot.
  525. SERVICE_DEMAND_START: Manual service startup.
  526. SERVICE_DISABLED: The service is disabled.
  527. Note that SERVICE_DELAYED_START is not supported on versions of Windows prior
  528. to Vista. NSSM will set the service to automatic startup if delayed start is
  529. unavailable.
  530. The Type parameter is used to query or set the service type. NSSM recognises
  531. all currently documented service types but will only allow setting one of two
  532. types:
  533. SERVICE_WIN32_OWN_PROCESS: A standalone service. This is the default.
  534. SERVICE_INTERACTIVE_PROCESS: A service which can interact with the desktop.
  535. Note that a service may only be configured as interactive if it runs under
  536. the LocalSystem account. The safe way to configure an interactive service
  537. is in two stages as follows.
  538. nssm reset <servicename> ObjectName
  539. nssm set <servicename> Type SERVICE_INTERACTIVE_PROCESS
  540. Controlling services using the command line
  541. -------------------------------------------
  542. NSSM offers rudimentary service control features.
  543. nssm start <servicename>
  544. nssm restart <servicename>
  545. nssm stop <servicename>
  546. nssm status <servicename>
  547. Removing services using the GUI
  548. -------------------------------
  549. NSSM can also remove services. Run
  550. nssm remove <servicename>
  551. to remove a service. You will prompted for confirmation before the service
  552. is removed. Try not to remove essential system services...
  553. Removing service using the command line
  554. ---------------------------------------
  555. To remove a service without confirmation from the GUI, run
  556. nssm remove <servicename> confirm
  557. Try not to remove essential system services...
  558. Logging
  559. -------
  560. NSSM logs to the Windows event log. It registers itself as an event log source
  561. and uses unique event IDs for each type of message it logs. New versions may
  562. add event types but existing event IDs will never be changed.
  563. Because of the way NSSM registers itself you should be aware that you may not
  564. be able to replace the NSSM binary if you have the event viewer open and that
  565. running multiple instances of NSSM from different locations may be confusing if
  566. they are not all the same version.
  567. Example usage
  568. -------------
  569. To install an Unreal Tournament server:
  570. nssm install UT2004 c:\games\ut2004\system\ucc.exe server
  571. To run the server as the "games" user:
  572. nssm set UT2004 ObjectName games password
  573. To configure the server to log to a file:
  574. nssm set UT2004 AppStdout c:\games\ut2004\service.log
  575. To restrict the server to a single CPU:
  576. nssm set UT2004 AppAffinity 0
  577. To remove the server:
  578. nssm remove UT2004 confirm
  579. To find out the service name of a service with a display name:
  580. nssm get "Background Intelligent Transfer Service" Name
  581. Building NSSM from source
  582. -------------------------
  583. NSSM is known to compile with Visual Studio 2008 and later. Older Visual
  584. Studio releases may or may not work if you install an appropriate SDK and
  585. edit the nssm.vcproj and nssm.sln files to set a lower version number.
  586. They are known not to work with default settings.
  587. NSSM will also compile with Visual Studio 2010 but the resulting executable
  588. will not run on versions of Windows older than XP SP2. If you require
  589. compatiblity with older Windows releases you should change the Platform
  590. Toolset to v90 in the General section of the project's Configuration
  591. Properties.
  592. Credits
  593. -------
  594. Thanks to Bernard Loh for finding a bug with service recovery.
  595. Thanks to Benjamin Mayrargue ( for adding 64-bit support.
  596. Thanks to Joel Reingold for spotting a command line truncation bug.
  597. Thanks to Arve Knudsen for spotting that child processes of the monitored
  598. application could be left running on service shutdown, and that a missing
  599. registry value for AppDirectory confused NSSM.
  600. Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling
  601. restarts.
  602. Thanks to Eugene Lifshitz for finding an edge case in CreateProcess() and for
  603. advising how to build correctly in paths containing spaces.
  604. Thanks to Rob Sharp for pointing out that NSSM did not respect the
  605. AppEnvironment registry value used by srvany.
  606. Thanks to Szymon Nowak for help with Windows 2000 compatibility.
  607. Thanks to François-Régis Tardy and Gildas le Nadan for French translation.
  608. Thanks to Emilio Frini for spotting that French was inadvertently set as
  609. the default language when the user's display language was not translated.
  610. Thanks to Riccardo Gusmeroli and Marco Certelli for Italian translation.
  611. Thanks to Eric Cheldelin for the inspiration to generate a Control-C event
  612. on shutdown.
  613. Thanks to Brian Baxter for suggesting how to escape quotes from the command
  614. prompt.
  615. Thanks to Russ Holmann for suggesting that the shutdown timeout be configurable.
  616. Thanks to Paul Spause for spotting a bug with default registry entries.
  617. Thanks to BUGHUNTER for spotting more GUI bugs.
  618. Thanks to Doug Watson for suggesting file rotation.
  619. Thanks to Арслан Сайдуганов for suggesting setting process priority.
  620. Thanks to Robert Middleton for suggestion and draft implementation of process
  621. affinity support.
  622. Thanks to Andrew RedzMax for suggesting an unconditional restart delay.
  623. Thanks to Bryan Senseman for noticing that applications with redirected stdout
  624. and/or stderr which attempt to read from stdin would fail.
  625. Thanks to Czenda Czendov for help with Visual Studio 2013 and Server 2012R2.
  626. Thanks to Alessandro Gherardi for reporting and draft fix of the bug whereby
  627. the second restart of the application would have a corrupted environment.
  628. Thanks to Hadrien Kohl for suggesting to disable the console window's menu.
  629. Thanks to Allen Vailliencourt for noticing bugs with configuring the service to
  630. run under a local user account.
  631. Thanks to Sam Townsend for noticing a regression with TerminateProcess().
  632. Thanks to Barrett Lewis for suggesting the option to skip terminating the
  633. application's child processes.
  634. Thanks to Miguel Angel Terrón for suggesting copy/truncate rotation.
  635. Thanks to Yuriy Lesiuk for suggesting setting the environment before querying
  636. the registry for parameters.
  637. Thanks to Gerald Haider for noticing that installing a service with NSSM in a
  638. path containing spaces was technically a security vulnerability.
  639. Thanks to Scott Ware for reporting a crash saving the environment on XP 32-bit.
  640. Thanks to Stefan and Michael Scherer for reporting a bug writing the event messages source.
  641. Thanks to Paul Baxter and Mathias Breiner for help with Visual Studio 2015.
  642. Licence
  643. -------
  644. NSSM is public domain. You may unconditionally use it and/or its source code
  645. for any purpose you wish.