Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file is optional in startDaemon() if options.command is set #599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
});
Expand Down