Skip to content

Commit 0b51577

Browse files
author
Dmitry Dolenko
authored
Revert "Update fork"
1 parent f831684 commit 0b51577

File tree

5 files changed

+64
-57
lines changed

5 files changed

+64
-57
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ syntax: glob
22
build
33
example/*.log
44
node_modules/
5-
package-lock.json

README.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ A program can then be added, removed and run as a service:
2323

2424
service.remove ("my-service");
2525

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");
2930
service.stop ();
3031
});
3132

@@ -56,7 +57,9 @@ with a `--add` parameter, and removes the created service when called with a
5657
console.trace(error);
5758
});
5859
} 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 () {
6063
service.stop (0);
6164
});
6265
@@ -124,7 +127,9 @@ program adding the services.
124127
Each of the service programs can simply start themselves as services using the
125128
following code:
126129

127-
service.run (function () {
130+
var logStream = fs.createWriteStream (process.argv[1] + ".log");
131+
132+
service.run (logStream, function () {
128133
service.stop (0);
129134
});
130135

@@ -261,27 +266,30 @@ The following example removes the service named `my-service`:
261266
console.trace(error);
262267
});
263268

264-
## service.run (callback)
269+
## service.run (stdoutLogStream, [stderrLogStream,] callback)
265270

266271
The `run()` function will attempt to run the program as a service.
267272

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.
278282

279283
The program should perform cleanup tasks and then call the `service.stop()`
280284
function.
281285

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");
283290

284-
service.run (function () {
291+
service.run (logStream, function () {
292+
console.log ("stop request received");
285293
service.stop ();
286294
});
287295

@@ -300,14 +308,23 @@ finished performing cleanup tasks.
300308
The following example stops the calling program specifying a return code of
301309
`0`, the function will not return:
302310

303-
service.run (function () {
311+
var logStream = fs.createWriteStream ("my-service.log");
312+
313+
service.run (logStream, function () {
314+
console.log ("stop request received");
304315
service.stop (0);
305316
});
306317

307318
# Example Programs
308319

309320
Example programs are included under the modules `example` directory.
310321

322+
# Bugs & Known Issues
323+
324+
None, yet!
325+
326+
Bug reports should be sent to <[email protected]>.
327+
311328
# Changes
312329

313330
## Version 1.0.0 - 30/12/2014
@@ -369,29 +386,13 @@ Example programs are included under the modules `example` directory.
369386
`__defineGetter__()` function
370387
* Specify dependancies when adding a service
371388

372-
## Version 2.0.0 - 12/02/2018
389+
# Roadmap
373390

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]>.
389392

390393
# License
391394

392-
Copyright (c) 2018 NoSpaceships Ltd <[email protected]>
393-
394-
Copyright (c) 2014 Stephen Vickers <[email protected]>
395+
Copyright (c) 2014 Stephen Vickers
395396

396397
Permission is hereby granted, free of charge, to any person obtaining a copy
397398
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
410411
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
411412
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
412413
THE SOFTWARE.
414+
415+
# Author
416+
417+
Stephen Vickers <[email protected]>

example/periodic-logger.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ if (process.argv[2] == "--add" && process.argv.length >= 4) {
3838
console.log(error.toString());
3939
});
4040
} else if (process.argv[2] == "--run") {
41+
var logStream = fs.createWriteStream (process.argv[1] + ".log");
4142
service.run (logStream, function () {
4243
service.stop (0);
4344
});
4445

45-
var logStream = fs.createWriteStream(process.argv[1] + ".log");
46-
4746
// Here is our long running code, simply print a date/time string to
4847
// our log file
4948
setInterval (function () {
50-
logStream.write(new Date ().toString () + "\n");
49+
console.log(new Date ().toString ());
5150
}, 1000);
5251
} else {
5352
usage ();

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,16 @@ function remove (name, cb) {
430430
}
431431
}
432432

433-
function run (stopCallback) {
433+
function run (stdoutLogStream, stderrLogStream, stopCallback) {
434+
if (! stopCallback) {
435+
stopCallback = stderrLogStream;
436+
stderrLogStream = stdoutLogStream;
437+
}
438+
434439
if (! runInitialised) {
440+
process.stdout.write = stdoutLogStream.write.bind(stdoutLogStream);
441+
process.stderr.write = stderrLogStream.write.bind(stderrLogStream);
442+
435443
if (os.platform() == "win32") {
436444
setInterval (function () {
437445
if (isStopRequested ()) {

package.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
{
22
"name": "os-service",
3-
"version": "2.1.3",
3+
"version": "1.5.0",
44
"description": "Run Node.JS programs as native Operating System Services.",
55
"main": "index.js",
66
"directories": {
77
"example": "example"
88
},
99
"dependencies": {
10-
"nan": "2.10.x"
10+
"nan": "2.3.x"
1111
},
12-
"contributors": [
12+
"contributors": [
1313
{
1414
"name": "Stephen Vickers",
15-
"email": "[email protected]"
16-
},
17-
{
18-
"name": "NoSpaceships Ltd",
19-
"email": "[email protected]"
20-
}
15+
"email": "[email protected]"
16+
}
2117
],
2218
"repository": {
2319
"type": "git",
24-
"url": "git://github.com/nospaceships/node-os-service.git"
20+
"url": "git://github.com/stephenwvickers/node-os-service.git"
2521
},
2622
"keywords": [
2723
"background-process",
@@ -30,10 +26,10 @@
3026
"linux-daemon",
3127
"linux-service",
3228
"service",
33-
"windows",
34-
"windows-daemon",
35-
"windows-service"
29+
"windows",
30+
"windows-daemon",
31+
"windows-service"
3632
],
37-
"author": "NoSpaceships Ltd <hello@nospaceships.com>",
33+
"author": "Stephen Vickers <stephen.vickers.sv@gmail.com>",
3834
"license": "MIT"
3935
}

0 commit comments

Comments
 (0)