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
2 changes: 1 addition & 1 deletion lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var daemon = function(config){
enumerable: true,
writable: false,
configurable: false,
value: config.maxRestarts || 3
value: (config.maxRestarts === 0) ? 0 : (config.maxRestarts || 3)
},

/**
Expand Down
21 changes: 16 additions & 5 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ argv.f = p.resolve(argv.f);
// Hack to force the wrapper process to stay open by launching a ghost socket server
var server = require('net').createServer().listen();

var delay = 1000;

/**
* @method monitor
* Monitor the process to make sure it is running
Expand All @@ -87,19 +89,25 @@ var monitor = function(exit){
if(!child.pid||exit){

// If the number of periodic starts exceeds the max, kill the process
if (starts >= argv.r){
if (starts >= argv.r && argv.r > 0){
if (new Date().getTime()-(max*1000) <= startTime.getTime()){
log.error('Too many restarts within the last '+max+' seconds. Please check the script.');
process.exit();
// delay, so log can write to event log, then exit
setTimeout(function () {
process.exit(1);
}, delay);
}
}

setTimeout(function(){
wait = wait * grow;
attempts += 1;
if (attempts > argv.m && argv.m >= 0){
if (attempts > argv.m && argv.m > 0){
log.error('Too many restarts. '+argv.f+' will not be restarted because the maximum number of total restarts has been exceeded.');
process.exit();
// delay, so log can write to event log, then exit
setTimeout(function () {
process.exit(2);
}, delay);
} else {
launch();
}
Expand Down Expand Up @@ -145,7 +153,10 @@ var launch = function(){
// If an error is thrown and the process is configured to exit, then kill the parent.
if (code !== 0 && argv.a == "yes"){
log.error(argv.f+' exited with error code '+code);
process.exit();
// delay, so log can write to event log, then exit
setTimeout(function () {
process.exit(3);
}, delay);
//server.unref();
}

Expand Down