Try to send Control-C event to application console.
[nssm.git] / README.txt
1 NSSM: The Non-Sucking Service Manager\r
2 Version 2.16, 2012-12-01\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 Usage\r
44 -----\r
45 In the usage notes below, arguments to the program may be written in angle \r
46 brackets and/or square brackets.  <string> means you must insert the \r
47 appropriate string and [<string>] means the string is optional.  See the \r
48 examples below...\r
49 \r
50 \r
51 Installation using the GUI\r
52 --------------------------\r
53 To install a service, run\r
54 \r
55     nssm install <servicename>\r
56 \r
57 You will be prompted to enter the full path to the application you wish \r
58 to run and any command line options to pass to that application.\r
59 \r
60 Use the system service manager (services.msc) to control advanced service \r
61 properties such as startup method and desktop interaction.  NSSM may \r
62 support these options at a later time...\r
63 \r
64 \r
65 Installation using the command line\r
66 -----------------------------------\r
67 To install a service, run\r
68 \r
69     nssm install <servicename> <application> [<options>]\r
70 \r
71 NSSM will then attempt to install a service which runs the named application \r
72 with the given options (if you specified any).\r
73 \r
74 Don't forget to enclose paths in "quotes" if they contain spaces!\r
75 \r
76 \r
77 Managing the service\r
78 --------------------\r
79 NSSM will launch the application listed in the registry when you send it a \r
80 start signal and will terminate it when you send a stop signal.  So far, so \r
81 much like srvany.  But NSSM is the Non-Sucking service manager and can take \r
82 action if/when the application dies.\r
83 \r
84 With no configuration from you, NSSM will try to restart itself if it notices\r
85 that the application died but you didn't send it a stop signal.  NSSM will\r
86 keep trying, pausing between each attempt, until the service is successfully\r
87 started or you send it a stop signal.\r
88 \r
89 NSSM will pause an increasingly longer time between subsequent restart attempts\r
90 if the service fails to start in a timely manner, up to a maximum of four\r
91 minutes.  This is so it does not consume an excessive amount of CPU time trying\r
92 to start a failed application over and over again.  If you identify the cause\r
93 of the failure and don't want to wait you can use the Windows service console\r
94 (where the service will be shown in Paused state) to send a continue signal to\r
95 NSSM and it will retry within a few seconds.\r
96 \r
97 By default, NSSM defines "a timely manner" to be within 1500 milliseconds.\r
98 You can change the threshold for the service by setting the number of\r
99 milliseconds as a REG_DWORD value in the registry at\r
100 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppThrottle.\r
101 \r
102 NSSM will look in the registry under\r
103 HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters\AppExit for\r
104 string (REG_EXPAND_SZ) values corresponding to the exit code of the application.\r
105 If the application exited with code 1, for instance, NSSM will look for a\r
106 string value under AppExit called "1" or, if it does not find it, will\r
107 fall back to the AppExit (Default) value.  You can find out the exit code\r
108 for the application by consulting the system event log.  NSSM will log the\r
109 exit code when the application exits.\r
110 \r
111 Based on the data found in the registry, NSSM will take one of three actions:\r
112 \r
113 If the value data is "Restart" NSSM will try to restart the application as\r
114 described above.  This is its default behaviour.\r
115 \r
116 If the value data is "Ignore" NSSM will not try to restart the application\r
117 but will continue running itself.  This emulates the (usually undesirable)\r
118 behaviour of srvany.  The Windows Services console would show the service\r
119 as still running even though the application has exited.\r
120 \r
121 If the value data is "Exit" NSSM will exit gracefully.  The Windows Services\r
122 console would show the service as stopped.  If you wish to provide\r
123 finer-grained control over service recovery you should use this code and\r
124 edit the failure action manually.  Please note that Windows versions prior\r
125 to Vista will not consider such an exit to be a failure.  On older versions\r
126 of Windows you should use "Suicide" instead.\r
127 \r
128 If the value data is "Suicide" NSSM will simulate a crash and exit without\r
129 informing the service manager.  This option should only be used for\r
130 pre-Vista systems where you wish to apply a service recovery action.  Note\r
131 that if the monitored application exits with code 0, NSSM will only honour a\r
132 request to suicide if you explicitly configure a registry key for exit code 0.\r
133 If only the default action is set to Suicide NSSM will instead exit gracefully.\r
134 \r
135 \r
136 Removing services using the GUI\r
137 -------------------------------\r
138 NSSM can also remove services.  Run\r
139 \r
140     nssm remove <servicename>\r
141 \r
142 to remove a service.  You will prompted for confirmation before the service \r
143 is removed.  Try not to remove essential system services...\r
144 \r
145 \r
146 Removing service using the command line\r
147 ---------------------------------------\r
148 To remove a service without confirmation from the GUI, run\r
149 \r
150     nssm remove <servicename> confirm\r
151 \r
152 Try not to remove essential system services...\r
153 \r
154 \r
155 Logging\r
156 -------\r
157 NSSM logs to the Windows event log.  It registers itself as an event log source\r
158 and uses unique event IDs for each type of message it logs.  New versions may\r
159 add event types but existing event IDs will never be changed.\r
160 \r
161 Because of the way NSSM registers itself you should be aware that you may not\r
162 be able to replace the NSSM binary if you have the event viewer open and that\r
163 running multiple instances of NSSM from different locations may be confusing if\r
164 they are not all the same version.\r
165 \r
166 \r
167 Example usage\r
168 -------------\r
169 To install an Unreal Tournament server:\r
170 \r
171     nssm install UT2004 c:\games\ut2004\system\ucc.exe server\r
172 \r
173 To remove the server:\r
174 \r
175     nssm remove UT2004 confirm\r
176 \r
177 \r
178 Building NSSM from source\r
179 -------------------------\r
180 NSSM is known to compile with Visual Studio 6, Visual Studio 2005 and Visual\r
181 Studio 2008.\r
182 \r
183 NSSM will also compile with Visual Studio 2010 but the resulting executable\r
184 will not run on versions of Windows older than XP SP2.\r
185 \r
186 \r
187 Credits\r
188 -------\r
189 Thanks to Bernard Loh for finding a bug with service recovery.\r
190 Thanks to Benjamin Mayrargue (www.softlion.com) for adding 64-bit support.\r
191 Thanks to Joel Reingold for spotting a command line truncation bug.\r
192 Thanks to Arve Knudsen for spotting that child processes of the monitored\r
193 application could be left running on service shutdown, and that a missing\r
194 registry value for AppDirectory confused NSSM.\r
195 Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling restarts.\r
196 Thanks to Eugene Lifshitz for finding an edge case in CreateProcess() and for\r
197 advising how to build messages.mc correctly in paths containing spaces.\r
198 Thanks to Rob Sharp for pointing out that NSSM did not respect the\r
199 AppEnvironment registry value used by srvany.\r
200 Thanks to Szymon Nowak for help with Windows 2000 compatibility.\r
201 Thanks to François-Régis Tardy for French translation.\r
202 Thanks to Emilio Frini for spotting that French was inadvertently set as\r
203 the default language when the user's display language was not translated.\r
204 Thanks to Riccardo Gusmeroli for Italian translation.\r
205 Thanks to Eric Cheldelin for the inspiration to generate a Control-C event\r
206 on shutdown.\r
207 \r
208 Licence\r
209 -------\r
210 NSSM is public domain.  You may unconditionally use it and/or its source code \r
211 for any purpose you wish.\r