diff --git a/bin/pm2 b/bin/pm2 index f044570e..4d90aba1 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -33,6 +33,7 @@ commander.version(pkg.version) .option('-e --error ', 'specify error log file') .option('-p --pid ', 'specify pid file') .option('--max-memory-restart ', 'specify max memory amount used to autorestart (in megaoctets)') + .option('--restart-delay ', 'specify a delay between restarts (in milliseconds)') .option('--env ', 'specify environment to get specific env variables (for JSON declaration)') .option('-x --execute-command', 'execute a program using fork system') .option('-u --user ', 'define user when generating startup script') @@ -48,7 +49,7 @@ commander.version(pkg.version) .option('--no-color', 'skip colors') .option('--no-vizion', 'start an app without vizion feature (versioning control)') .option('--no-autorestart', 'start an app without automatic restart') - .option('--no-treekill', 'Only kill main process not detached childrens') + .option('--no-treekill', 'Only kill the main process, not detached children') .usage('[cmd] app'); @@ -478,7 +479,7 @@ commander.command('startup [platform]') // // Logrotate -// +// commander.command('logrotate') .description('copy default logrotate configuration') .action(function(cmd) { diff --git a/lib/Common.js b/lib/Common.js index 447fb704..168ca027 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -112,7 +112,7 @@ Common.prepareAppConf = function(app, cwd, outputter) { /** * Here we put the default exec mode */ - if (!app.exec_mode && app.instances > 0) { + if (!app.exec_mode && app.instances > 1) { app.exec_mode = 'cluster_mode'; } else if (!app.exec_mode) { app.exec_mode = 'fork_mode'; diff --git a/lib/God.js b/lib/God.js index a4d8289e..61589363 100644 --- a/lib/God.js +++ b/lib/God.js @@ -321,11 +321,17 @@ God.handleExit = function handleExit(clu, exit_code) { return false; } - if (!stopping) - proc.pm2_env.restart_time += 1; + var restart_delay = 0; + if (proc.pm2_env.restart_delay !== undefined && !isNaN(parseInt(proc.pm2_env.restart_delay))) { + restart_delay = parseInt(proc.pm2_env.restart_delay); + } - if (!stopping && !overlimit) - this.executeApp(proc.pm2_env); + if (!stopping && !overlimit) { + setTimeout(function() { + proc.pm2_env.restart_time += 1; + God.executeApp(proc.pm2_env); + }, restart_delay); + } return false; }; diff --git a/lib/schema.json b/lib/schema.json index 5454754e..533f910e 100644 --- a/lib/schema.json +++ b/lib/schema.json @@ -27,6 +27,9 @@ "ext_type": "sbyte", "desc": "it should be a NUMBER - byte, \"[NUMBER]G\"(Gigabyte), \"[NUMBER]M\"(Megabyte) or \"[NUMBER]K\"(Kilobyte)" }, + "restart_delay": { + "type" : "number" + }, "next_gen_js" : { "type" : "boolean" }, diff --git a/test/bash/reset.sh b/test/bash/reset.sh index 71c3562b..78f1ca94 100644 --- a/test/bash/reset.sh +++ b/test/bash/reset.sh @@ -44,3 +44,11 @@ should 'should process restarted' 'restart_time: 3' 5 $pm2 reset all should 'should process reseted' 'restart_time: 0' 5 + +# +# Restart delay test +# + +$pm2 delete all +$pm2 start killtoofast.js --restart-delay 5000 +should 'should process not have been restarted yet' 'restart_time: 0' 1