@@ -23,9 +23,10 @@ A program can then be added, removed and run as a service:
23
23
24
24
service.remove ("my-service");
25
25
26
- service.run (function () {
27
- // Stop request received (i.e. a kill signal on Linux or from the
28
- // Service Control Manager on Windows), so let's stop!
26
+ var logStream = fs.createWriteStream ("my-service.log");
27
+
28
+ service.run (logStream, function () {
29
+ console.log ("stop request received");
29
30
service.stop ();
30
31
});
31
32
@@ -56,7 +57,9 @@ with a `--add` parameter, and removes the created service when called with a
56
57
console.trace(error);
57
58
});
58
59
} else if (process.argv[2] == "--run") {
59
- service.run (function () {
60
+ var logStream = fs.createWriteStream (process.argv[1] + ".log");
61
+
62
+ service.run (logStream, function () {
60
63
service.stop (0);
61
64
});
62
65
@@ -124,7 +127,9 @@ program adding the services.
124
127
Each of the service programs can simply start themselves as services using the
125
128
following code:
126
129
127
- service.run (function () {
130
+ var logStream = fs.createWriteStream (process.argv[1] + ".log");
131
+
132
+ service.run (logStream, function () {
128
133
service.stop (0);
129
134
});
130
135
@@ -261,27 +266,30 @@ The following example removes the service named `my-service`:
261
266
console.trace(error);
262
267
});
263
268
264
- ## service.run (callback)
269
+ ## service.run (stdoutLogStream, [ stderrLogStream, ] callback)
265
270
266
271
The ` run() ` function will attempt to run the program as a service.
267
272
268
- ** NOTE** When run the service will NOT make any changes to the ` process.stdout `
269
- and ` process.stderr ` streams. Users are required to utilise whatever logging
270
- modules they require to managing process logging and its destination. Older
271
- versions of this module (versions before 2.0.0) would support re-directing
272
- these streams to a specific writeable stream, support for that was removed in
273
- version 2.0.0.
274
-
275
- The ` callback ` function will be called when the service receives a stop request,
276
- e.g. because the Windows Service Controller was used to send a stop request to
277
- the service, or a ` SIGTERM ` signal was received.
273
+ The programs ` process.stdout ` stream will be replaced with the
274
+ ` stdoutLogStream ` parameter, and the programs ` process.stderr ` stream
275
+ replaced with the ` stdoutLogStream ` parameter (this allows the redirection of
276
+ all ` console.log() ` type calls to a service specific log file). If the
277
+ ` stderrLogStream ` parameter is not specified the programs ` process.stderr `
278
+ stream will be replaced with the ` stdoutLogStream ` parameter. The ` callback `
279
+ function will be called when the service receives a stop request, e.g. because
280
+ the Windows Service Controller was used to send a stop request to the service,
281
+ or a ` SIGTERM ` signal was received.
278
282
279
283
The program should perform cleanup tasks and then call the ` service.stop() `
280
284
function.
281
285
282
- The following example starts a program as a service:
286
+ The following example starts a program as a service, it uses the same log
287
+ stream for standard output and standard error:
288
+
289
+ var logStream = fs.createWriteStream ("my-service.log");
283
290
284
- service.run (function () {
291
+ service.run (logStream, function () {
292
+ console.log ("stop request received");
285
293
service.stop ();
286
294
});
287
295
@@ -300,14 +308,23 @@ finished performing cleanup tasks.
300
308
The following example stops the calling program specifying a return code of
301
309
` 0 ` , the function will not return:
302
310
303
- service.run (function () {
311
+ var logStream = fs.createWriteStream ("my-service.log");
312
+
313
+ service.run (logStream, function () {
314
+ console.log ("stop request received");
304
315
service.stop (0);
305
316
});
306
317
307
318
# Example Programs
308
319
309
320
Example programs are included under the modules ` example ` directory.
310
321
322
+ # Bugs & Known Issues
323
+
324
+ None, yet!
325
+
326
+ Bug reports should be sent to <
[email protected] >.
327
+
311
328
# Changes
312
329
313
330
## Version 1.0.0 - 30/12/2014
@@ -369,29 +386,13 @@ Example programs are included under the modules `example` directory.
369
386
` __defineGetter__() ` function
370
387
* Specify dependancies when adding a service
371
388
372
- ## Version 2.0.0 - 12/02/2018
389
+ # Roadmap
373
390
374
- * Remove support to override stdout/stderr with a logstream (let users use
375
- their required/own logging modules) - the run() function now only accepts
376
- one argument whereas previously this was either two or three
377
-
378
- ## Version 2.1.0 - 02/05/2018
379
-
380
- * Support Node.js 10
381
-
382
- ## Version 2.1.2 - 06/06/2018
383
-
384
- * Set NoSpaceships Ltd to be the owner and maintainer
385
-
386
- ## Version 2.1.3 - 07/06/2018
387
-
388
- * Remove redundant sections from README.md
391
+ Suggestions and requirements should be sent to <
[email protected] >.
389
392
390
393
# License
391
394
392
- Copyright (c) 2018 NoSpaceships Ltd
< [email protected] >
393
-
394
- Copyright (c) 2014 Stephen Vickers <
[email protected] >
395
+ Copyright (c) 2014 Stephen Vickers
395
396
396
397
Permission is hereby granted, free of charge, to any person obtaining a copy
397
398
of this software and associated documentation files (the "Software"), to deal
@@ -410,3 +411,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
410
411
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
411
412
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
412
413
THE SOFTWARE.
414
+
415
+ # Author
416
+
417
+ Stephen Vickers <
[email protected] >
0 commit comments