From 34850b74a19ca122f12a365086c7261bb773caa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Fri, 5 Sep 2014 22:51:16 +0200 Subject: [PATCH] `file` is optional in startDaemon() if `options.command` is set --- README.md | 2 +- lib/forever.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3257c733..e484fb30 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ _Synchronously_ sets the specified configuration (config) for the forever module Starts a script with forever. ### forever.startDaemon (file, options) -Starts a script with forever as a daemon. WARNING: Will daemonize the current process. +Starts a script with forever as a daemon. WARNING: Will daemonize the current process. `file` field can be ommited when `options.command` is set. ### forever.stop (index) Stops the forever daemon script at the specified index. These indices are the same as those returned by forever.list(). This method returns an EventEmitter that raises the 'stop' event when complete. diff --git a/lib/forever.js b/lib/forever.js index 6a3a7964..10c0befa 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -384,6 +384,15 @@ forever.start = function (script, options) { // Starts a script with forever as a daemon // forever.startDaemon = function (script, options) { + if (script && !Array.isArray(script) && typeof script != 'string') { + options = script; + script = undefined; + } + + if (!script && !(options && options.command)) { + throw new SyntaxError("One of 'script' or 'options.command' fields must be defined") + } + options = options || {}; options.uid = options.uid || utile.randomString(4).replace(/^\-/, '_'); options.logFile = forever.logFilePath(options.logFile || forever.config.get('logFile') || options.uid + '.log'); @@ -399,9 +408,11 @@ forever.startDaemon = function (script, options) { // outFD = fs.openSync(options.logFile, 'a'); errFD = fs.openSync(options.logFile, 'a'); - monitorPath = path.resolve(__dirname, '..', 'bin', 'monitor'); - monitor = spawn(process.execPath, [monitorPath, script], { + var args = [path.resolve(__dirname, '..', 'bin', 'monitor')]; + if(script) args.push(script); + + monitor = spawn(process.execPath, args, { stdio: ['ipc', outFD, errFD], detached: true });