From aee5eb3903705273d0b81550300c7f4289d124d7 Mon Sep 17 00:00:00 2001 From: Nathan Smith Date: Thu, 24 Mar 2016 15:38:08 -0500 Subject: [PATCH 1/2] Implement command line args for script/program. --- lib/daemon.js | 2 +- lib/wrapper.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/daemon.js b/lib/daemon.js index a282785..801e13f 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -101,7 +101,7 @@ var daemon = function(config){ return require('./winsw').generateXml({ name: this.name, id: this._exe, - script: '"'+wrapper+'" -f "'+this.script+'" -l "'+this.name+'" -g '+this.grow + script: '"'+wrapper+'" -f "'+this.script+'"'+(config.parameters ? ' --parameters "'+config.parameters+'"' : '')+' -l "'+this.name+'" -g '+this.grow +' -w '+this.wait+(this.maxRetries!==null?' -m '+this.maxRetries:'') +' -r '+this.maxRestarts+' -a '+(this.abortOnError==true?'y':'n') + (config.cwd ? ' -d "'+config.cwd+'"' : ''), diff --git a/lib/wrapper.js b/lib/wrapper.js index 4a9765d..9dfe1c2 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -49,6 +49,8 @@ var Logger = require('./eventlog'), .check(function(argv){ return ['y','n','yes','no'].indexOf(argv.a.trim().toLowerCase()) >= 0; }) + .alias('args', 'parameters') + .describe('parameters', 'Parameters/args that you send into your program/script.') .argv, log = new Logger(argv.e == undefined ? argv.l : {source:argv.l,eventlog:argv.e}), fork = require('child_process').fork, @@ -58,7 +60,7 @@ var Logger = require('./eventlog'), attempts = 0, startTime = null, starts = 0, - child = null + child = null, forcekill = false; if (argv.d){ @@ -135,8 +137,13 @@ var launch = function(){ // Fork the child process var opts = {env:process.env}; + var args; + if (argv.args) { + args = argv.args.split(' '); + } + if (argv.d) opts.cwd = argv.d; - child = fork(script,opts); + child = fork(script, args, opts); // When the child dies, attempt to restart based on configuration child.on('exit',function(code){ From 2b5d7b15abf47ac9fc9ba48ac49503a3963f61fa Mon Sep 17 00:00:00 2001 From: Nathan Smith Date: Fri, 25 Mar 2016 14:05:49 -0500 Subject: [PATCH 2/2] update READ with comand line parameters instructions. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index f8f9137..b411334 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,20 @@ var svc = new Service({ }); ``` +### Command Line Parameters +If your program or script takes arguments or parameters, you can define them by using the `parameters` option in in the config object. + +```js +var projectPath = require('path').resolve(__dirname); +var svc = new Service({ + name:'Hello World', + description: 'The nodejs.org example web server.', + script: 'C:\\path\\to\\helloworld.js', + parameters: '--port 1234 --hot --files ./path/to/some/file.js + cwd: projectPath +}); +``` +***Note*** In some cases it will be beneficial for you to include the `cwd` option pointing to your project directory. Remember to use an absolute path. ### User Account Attributes