Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var svc = new Service({
]
//, workingDirectory: '...'
//, allowServiceLogon: true
//, autoServiceRestart: true
});

// Listen for the "install" event, which indicates the
Expand Down Expand Up @@ -257,6 +258,18 @@ var svc = new Service({
dependsOn: ["serviceA"]
});
```
### Handle service level process death

The service can also be restarted by windows in the event that the underlying wrapper process dies.

```js
var svc = new Service({
name:'Hello World',
description: 'The nodejs.org example web server.',
script: 'C:\\path\\to\\helloworld.js',
autoServiceRestart: true
});
```

### Cleaning Up: Uninstall a Service

Expand Down
3 changes: 2 additions & 1 deletion example/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var svc = new Service({
env:{
name: "NODE_ENV",
value: "production"
}
},
autoServiceRestart: false
});

// Listen for the "install" event, which indicates the
Expand Down
205 changes: 205 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"node-windows": "^1.0.0-beta.7"
"node-windows": "^1.0.0-beta.8"
}
}
9 changes: 9 additions & 0 deletions lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ var daemon = function (config) {
workingdirectory: this.workingdirectory,
stopparentfirst: this.stopparentfirst,
stoptimeout: this.stoptimeout,
autoServiceRestart: this.autoServiceRestart,
logmode: this.logmode,
logging: config.logging,
allowServiceLogon: config.allowServiceLogon,
Expand Down Expand Up @@ -339,6 +340,14 @@ var daemon = function (config) {
value: config.description || ''
},

// setup as a restarting node service
autoServiceRestart: {
enumerable: true,
writable: false,
configurable: false,
value: config.autoServiceRestart || false
},

/**
* @property {Object} [user]
* If you need to specify a specific user or particular credentials to manage a service, the following
Expand Down
5 changes: 5 additions & 0 deletions lib/winsw.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ console.log({loc: 'winsw.js ~line 77', xml, config})
}
}

if(config.autoServiceRestart) {
// add <onfailure action="restart" delay="10 sec"/>
xml.push({onfailure: [{ _attr: { action: 'restart', delay: '10 sec' }}]});
}

// if no working directory specified, use current working directory
// that this process was launched with
xml.push({workingdirectory: config.workingdirectory || process.cwd()});
Expand Down
13 changes: 5 additions & 8 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,8 @@ if (typeof argv.m === 'string') {
// Set the absolute path of the file
argv.f = p.resolve(argv.f);

// Hack to force the wrapper process to stay open by launching a ghost socket server
var server = net.createServer().listen();

server.on('error', function (err) {
launch('warn', err.message);
server = net.createServer().listen();
});
// Force the wrapper process to stay open by creating a heartbeat
setInterval(() => {}, 86400000);

/**
* @method monitor
Expand Down Expand Up @@ -212,7 +207,9 @@ process.on("SIGINT", killkid);
process.on("SIGTERM", killkid);

process.on('uncaughtException', function (err) {
launch('warn', err.message);
console.log('node-windows Wrapper service: process uncaught exception:');
console.log(err);
process.exit(1);
});

// Launch the process
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-windows",
"version": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"description": "Support for Windows services, event logging, UAC, and several helper methods for interacting with the OS.",
"keywords": [
"ngn",
Expand Down