node-windows
Advanced tools
Comparing version 0.1.14 to 1.0.0-beta.1
@@ -103,2 +103,3 @@ /** | ||
'--file', this.script, | ||
'--scriptoptions='+this.scriptOptions, | ||
'--log', this.name + ' ' + 'wrapper', | ||
@@ -123,2 +124,3 @@ '--grow', this.grow, | ||
script: wrapper, | ||
scriptOptions: this.scriptOptions, | ||
wrapperArgs: wrapperArgs, | ||
@@ -128,6 +130,9 @@ description: this.description, | ||
env: config.env, | ||
execPath: this.execPath, | ||
logOnAs: this.logOnAs, | ||
workingdirectory: this.workingdirectory, | ||
stopparentfirst: this.stopparentfirst, | ||
stoptimeout: this.stoptimeout | ||
stoptimeout: this.stoptimeout, | ||
logmode: this.logmode, | ||
logging: config.logging | ||
}); | ||
@@ -153,3 +158,3 @@ } | ||
configurable: false, | ||
value: config.maxRetries || null | ||
value: config.hasOwnProperty('maxRetries') ? config.maxRetries : null | ||
}, | ||
@@ -177,3 +182,3 @@ | ||
configurable: false, | ||
value: config.stoptimeout || 30 | ||
value: config.hasOwnProperty('stoptimeout') ? config.stoptimeout : 30 | ||
}, | ||
@@ -191,3 +196,14 @@ | ||
}, | ||
/** | ||
* @cfg {string} [scriptOptions=''] | ||
* Options to be passed to the script. | ||
*/ | ||
scriptOptions: { | ||
enumerable: true, | ||
writable: false, | ||
configurable: false, | ||
value: config.scriptOptions || '' | ||
}, | ||
/** | ||
@@ -202,3 +218,3 @@ * @cfg {Number} [maxRestarts=3] | ||
configurable: false, | ||
value: config.maxRestarts || 3 | ||
value: config.hasOwnProperty('maxRestarts') ? config.maxRestarts : 3 | ||
}, | ||
@@ -610,13 +626,22 @@ | ||
// Remove all other files | ||
var _files = fs.readdirSync(me.root); | ||
_files.forEach(function(f){ | ||
rm(f); | ||
var _other_files = fs.readdirSync(me.root).filter(function (file) { | ||
const regex = /^.+\.((wrapper|out|err)\.log)|(exe|xml)$/g | ||
return !regex.exec(file) | ||
}) | ||
_other_files.forEach(function(f){ | ||
rm(f) | ||
}); | ||
if (me.root !== path.dirname(me.script)){ | ||
fs.rmdir(me.root,function(){ | ||
sleep(1); | ||
// Remove the dir iff it's empty | ||
if (fs.readdirSync(me.root).length === 0) { | ||
if (me.root !== path.dirname(me.script)){ | ||
fs.rmdir(me.root,function(){ | ||
sleep(1); | ||
me.emit('uninstall'); | ||
}); | ||
} else { | ||
me.emit('uninstall'); | ||
}); | ||
} else { | ||
} | ||
} | ||
else { | ||
me.emit('uninstall'); | ||
@@ -623,0 +648,0 @@ } |
@@ -45,2 +45,3 @@ /** | ||
var wincmd = require('./binaries'), | ||
exec = require("child_process").exec, | ||
eventlogs = ['APPLICATION','SYSTEM'], | ||
@@ -51,5 +52,8 @@ validtypes = ['ERROR','WARNING','INFORMATION','SUCCESSAUDIT','FAILUREAUDIT']; | ||
var write = function(log,src,type,msg,id,callback){ | ||
var cmd; | ||
if (msg == null) {return}; | ||
if (msg.trim().length == 0) {return}; | ||
msg = msg.replace(/\r\n|\n\r|\r|\n/g, "\f") | ||
@@ -63,3 +67,11 @@ log = log || 'APPLICATION'; | ||
wincmd.elevate("eventcreate /L "+log+" /T "+type+" /SO \""+src+"\" /D \""+msg+"\" /ID "+id,callback); | ||
cmd = "eventcreate /L "+log+" /T "+type+" /SO \""+src+"\" /D \""+msg+"\" /ID "+id; | ||
exec(cmd, function(err) { | ||
if (err && err.message.indexOf("Access is Denied")) { | ||
wincmd.elevate(cmd, callback); | ||
} else if (callback){ | ||
callback(err); | ||
} | ||
}); | ||
}; | ||
@@ -66,0 +78,0 @@ |
@@ -20,2 +20,6 @@ module.exports = { | ||
* - *logmode* Valid values include `rotate` (default), `reset` (clear log), `roll` (move to .old), and `append`. | ||
* - *logging* Supersedes *logmode*. Object of form `{mode: 'append'}`, | ||
* `{mode: 'reset'}`, `{mode: 'none'}`, `{mode: 'roll-by-time', pattern: 'yyyMMdd'}`, | ||
* or `{mode: 'roll-by-size', sizeThreshold: 10240, keepFiles: 8}` (all attributes optional, | ||
* example shows defaults). See [winsw docs](https://github.com/kohsuke/winsw/tree/winsw-1.17#logging). | ||
* - *logpath* The absolute path to the directory where logs should be stored. Defaults to the current directory. | ||
@@ -69,4 +73,3 @@ * - *dependencies* A comma delimited list or array of process dependencies. | ||
{description: config.description||''}, | ||
{executable: process.execPath}, | ||
{logmode: config.logmode||'rotate'} | ||
{executable: config.execPath || process.execPath} | ||
]; | ||
@@ -78,2 +81,17 @@ | ||
// Optionally add logging values, defaulting to logmode | ||
if (config.logging) { | ||
var logcontent = [{_attr: {mode: (config.logging.mode || 'append')}}]; | ||
if (config.logging.mode === 'roll-by-time') { | ||
logcontent.push({pattern: (config.logging.pattern || 'yyyMMdd')}); | ||
} | ||
if (config.logging.mode === 'roll-by-size') { | ||
logcontent.push({sizeThreshold: (config.logging.sizeThreshold || 10240)}); | ||
logcontent.push({keepFiles: (config.logging.keepFiles || 8)}); | ||
} | ||
xml.push({log: logcontent}); | ||
} | ||
else { | ||
xml.push({logmode: config.logmode||'rotate'}); | ||
} | ||
@@ -108,10 +126,8 @@ // Optionally add log path | ||
// optionally set the service logon credentials | ||
if (config.logOnAs && config.logOnAs.account && config.logOnAs.password && | ||
config.logOnAs.domain) | ||
{ | ||
if (config.logOnAs) { | ||
xml.push({ | ||
serviceaccount: [ | ||
{domain: config.logOnAs.domain}, | ||
{user: config.logOnAs.account}, | ||
{password: config.logOnAs.password} | ||
{domain: config.logOnAs.domain || 'NT AUTHORITY'}, | ||
{user: config.logOnAs.account || 'LocalSystem'}, | ||
{password: config.logOnAs.password || ''} | ||
] | ||
@@ -165,2 +181,2 @@ }); | ||
} | ||
} | ||
} |
// Handle input parameters | ||
var Logger = require('./eventlog'), | ||
optimist = require('optimist'), | ||
net = require('net'), | ||
max = 60, | ||
@@ -15,2 +16,3 @@ p = require('path'), | ||
}) | ||
.describe('scriptoptions','The options to be sent to the script.') | ||
.alias('d','cwd') | ||
@@ -87,4 +89,9 @@ .describe('cwd','The absolute path of the current working directory of the script to be run as a process.') | ||
// Hack to force the wrapper process to stay open by launching a ghost socket server | ||
var server = require('net').createServer().listen(); | ||
var server = net.createServer().listen(); | ||
server.on('error', function (err) { | ||
launch('warn', err.message); | ||
server = net.createServer().listen(); | ||
}); | ||
/** | ||
@@ -153,5 +160,7 @@ * @method monitor | ||
var opts = {env:process.env}; | ||
var args = []; | ||
if (argv.d) opts.cwd = argv.d; | ||
if (argv.s) opts.detached = true; | ||
child = fork(script,opts); | ||
if (argv.scriptoptions) args = argv.scriptoptions.split(' '); | ||
child = fork(script,args,opts); | ||
@@ -179,6 +188,10 @@ // When the child dies, attempt to restart based on configuration | ||
forcekill = true; | ||
if (argv.s) { | ||
child.send('shutdown'); | ||
if (child) { | ||
if (argv.s) { | ||
child.send('shutdown'); | ||
} else { | ||
child.kill(); | ||
} | ||
} else { | ||
child.kill(); | ||
log.warn('Attempted to kill an unrecognized process.') | ||
} | ||
@@ -191,3 +204,7 @@ } | ||
process.on('uncaughtException', function(err) { | ||
launch('warn', err.message); | ||
}); | ||
// Launch the process | ||
launch('info', 'Starting ' + argv.f); | ||
launch('info', 'Starting ' + argv.f); |
{ | ||
"name": "node-windows", | ||
"version": "0.1.14", | ||
"version": "1.0.0-beta.1", | ||
"description": "Support for Windows services, event logging, UAC, and several helper methods for interacting with the OS.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,13 +0,16 @@ | ||
# Update (2/11/17) | ||
# node-windows | ||
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/coreybutler/node-windows?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
I no longer have enough time to properly maintain this project and am seeking a new primary maintainer. | ||
A number of issues that have been lingering since 2015 have finally been resolved, including .NET 4+ support. | ||
This project has gained traction for two reasons: | ||
The number of issues between this project and it's sister projects ([node-mac](https://github.com/coreybutler/node-mac) & [node-linux](https://github.com/coreybutler/node-linux)) are accruing at a rate that deserves more attention than I can provide on my own. I'm actively looking for maintainers to help run this project. Please get in touch via gitter if you're interested. | ||
1. It works well on Windows. | ||
1. The same API can be used on macOS and Linux. | ||
[![NPM version](https://badge.fury.io/js/node-windows.png)](http://badge.fury.io/js/node-windows) | ||
[![NGN Dependencies](https://david-dm.org/coreybutler/node-windows.png)](https://david-dm.org/coreybutler/node-windows) | ||
[![Build](https://api.travis-ci.org/coreybutler/node-windows.png)](https://travis-ci.org/coreybutler/node-windows) | ||
The ideal maintainer would also support or at least closely work with the maintainer of ([node-mac](https://github.com/coreybutler/node-mac) & [node-linux](https://github.com/coreybutler/node-linux)). Please get in touch if you are interested in taking over. | ||
![NPM version](https://badge.fury.io/js/node-windows.png) | ||
![NGN Dependencies](https://david-dm.org/coreybutler/node-windows.png) | ||
![Build](https://api.travis-ci.org/coreybutler/node-windows.png) | ||
Follow the author on [G+](https://plus.google.com/u/1/111169756342687497578?rel=author) | ||
@@ -82,3 +85,7 @@ or [Twitter (@goldglovecb)](http://twitter.com/goldglovecb). | ||
description: 'The nodejs.org example web server.', | ||
script: 'C:\\path\\to\\helloworld.js' | ||
script: 'C:\\path\\to\\helloworld.js', | ||
nodeOptions: [ | ||
'--harmony', | ||
'--max_old_space_size=4096' | ||
] | ||
}); | ||
@@ -107,2 +114,3 @@ | ||
- _uninstall_ - Fired when an uninstallation is complete. | ||
- _alreadyuninstalled_ - Fired when an uninstall is requested and no installation exists. | ||
- _start_ - Fired when the new service is started. | ||
@@ -120,2 +128,16 @@ - _stop_ - Fired when the service is stopped. | ||
### Command-line Options | ||
It may be desired to specify command-line switches to your script. You can do this by setting the `scriptOptions` within the service config: | ||
```js | ||
var svc = new Service({ | ||
name:'Hello World', | ||
description: 'The nodejs.org example web server.', | ||
script: 'C:\\path\\to\\helloworld.js', | ||
scriptOptions: '-c C:\\path\\to\\somewhere\\special -i' | ||
}); | ||
``` | ||
### Environment Variables | ||
@@ -155,2 +177,16 @@ | ||
### Node Executable Path | ||
There are times when you may want to specify a specific `node` executable to use to run your script. You can do this by setting the `execPath` in the service config, as shown below: | ||
```js | ||
var svc = new Service({ | ||
name:'Hello World', | ||
description: 'The nodejs.org example web server.', | ||
script: 'C:\\path\\to\\helloworld.js', | ||
execPath: 'C:\\path\\to\\specific\\node.exe' | ||
}); | ||
``` | ||
### User Account Attributes | ||
@@ -176,5 +212,5 @@ | ||
svc.user.domain = 'mydomain.local'; | ||
svc.user.account = 'username'; | ||
svc.user.password = 'password'; | ||
svc.logOnAs.domain = 'mydomain.local'; | ||
svc.logOnAs.account = 'username'; | ||
svc.logOnAs.password = 'password'; | ||
... | ||
@@ -181,0 +217,0 @@ ``` |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
178808
1491
553
9
6