diff --git a/lib/API.js b/lib/API.js index 945c822d4..0e2bed944 100644 --- a/lib/API.js +++ b/lib/API.js @@ -1630,6 +1630,8 @@ class API { delete appConf.vizion; if (appConf.automation === true) delete appConf.automation; + if (appConf.autostart === true) + delete appConf.autostart; if (appConf.autorestart === true) delete appConf.autorestart; diff --git a/lib/API/schema.json b/lib/API/schema.json index fc5f868cd..7debd78d0 100644 --- a/lib/API/schema.json +++ b/lib/API/schema.json @@ -187,6 +187,12 @@ "docDefault" : "True", "docDescription": "Enable or disable the versioning metadatas (vizion library)" }, + "autostart": { + "type": "boolean", + "default": true, + "docDefault": "True", + "docDescription": "Enable or disable auto start when adding process" + }, "autorestart": { "type": "boolean", "default": true, diff --git a/lib/Common.js b/lib/Common.js index 1331dcb78..036e2dd56 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -565,7 +565,7 @@ Common.safeExtend = function(origin, add){ if (!add || typeof add != 'object') return origin; //Ignore PM2's set environment variables from the nested env - var keysToIgnore = ['name', 'exec_mode', 'env', 'args', 'pm_cwd', 'exec_interpreter', 'pm_exec_path', 'node_args', 'pm_out_log_path', 'pm_err_log_path', 'pm_pid_path', 'pm_id', 'status', 'pm_uptime', 'created_at', 'windowsHide', 'username', 'merge_logs', 'kill_retry_time', 'prev_restart_delay', 'instance_var', 'unstable_restarts', 'restart_time', 'axm_actions', 'pmx_module', 'command', 'watch', 'filter_env', 'versioning', 'vizion_runing', 'MODULE_DEBUG', 'pmx', 'axm_options', 'created_at', 'watch', 'vizion', 'axm_dynamic', 'axm_monitor', 'instances', 'automation', 'autorestart', 'stop_exit_codes', 'unstable_restart', 'treekill', 'exit_code', 'vizion']; + var keysToIgnore = ['name', 'exec_mode', 'env', 'args', 'pm_cwd', 'exec_interpreter', 'pm_exec_path', 'node_args', 'pm_out_log_path', 'pm_err_log_path', 'pm_pid_path', 'pm_id', 'status', 'pm_uptime', 'created_at', 'windowsHide', 'username', 'merge_logs', 'kill_retry_time', 'prev_restart_delay', 'instance_var', 'unstable_restarts', 'restart_time', 'axm_actions', 'pmx_module', 'command', 'watch', 'filter_env', 'versioning', 'vizion_runing', 'MODULE_DEBUG', 'pmx', 'axm_options', 'created_at', 'watch', 'vizion', 'axm_dynamic', 'axm_monitor', 'instances', 'automation', 'autostart', 'autorestart', 'stop_exit_codes', 'unstable_restart', 'treekill', 'exit_code', 'vizion']; var keys = Object.keys(add); var i = keys.length; diff --git a/lib/God.js b/lib/God.js index 620e5b5d4..af34baa74 100644 --- a/lib/God.js +++ b/lib/God.js @@ -168,7 +168,7 @@ God.executeApp = function executeApp(env, cb) { Utility.extend(env_copy, env_copy.env); - env_copy['status'] = cst.LAUNCHING_STATUS; + env_copy['status'] = env.autostart ? cst.LAUNCHING_STATUS : cst.STOPPED_STATUS; env_copy['pm_uptime'] = Date.now(); env_copy['axm_actions'] = []; env_copy['axm_monitor'] = {}; @@ -211,6 +211,12 @@ God.executeApp = function executeApp(env, cb) { God.registerCron(env_copy) + if(!env_copy['autostart']) { + var clu = {pm2_env: env_copy, process: {pid: 0}}; + God.clusters_db[env_copy.pm_id] = clu; + return cb(null, clu); + } + /** Callback when application is launched */ var readyCb = function ready(proc) { // If vizion enabled run versioning retrieval system diff --git a/lib/binaries/CLI.js b/lib/binaries/CLI.js index 36f8af6dc..a8fb94035 100644 --- a/lib/binaries/CLI.js +++ b/lib/binaries/CLI.js @@ -76,6 +76,7 @@ commander.version(pkg.version) .option('--watch-delay ', 'specify a restart delay after changing files (--watch-delay 4 (in sec) or 4000ms)') .option('--no-color', 'skip colors') .option('--no-vizion', 'start an app without vizion feature (versioning control)') + .option('--no-autostart', 'add an app without automatic start') .option('--no-autorestart', 'start an app without automatic restart') .option('--stop-exit-codes ', 'specify a list of exit codes that should skip automatic restart') .option('--no-treekill', 'Only kill the main process, not detached children') diff --git a/lib/binaries/DevCLI.js b/lib/binaries/DevCLI.js index b1e2bf79a..78b443c76 100644 --- a/lib/binaries/DevCLI.js +++ b/lib/binaries/DevCLI.js @@ -65,6 +65,7 @@ function run(cmd, opts) { var timestamp = opts.timestamp; opts.watch = true; + opts.autostart = true; opts.autorestart = true; opts.restart_delay = 1000 if (opts.autoExit) diff --git a/lib/binaries/Runtime4Docker.js b/lib/binaries/Runtime4Docker.js index 67ee8d657..e9b6003e9 100644 --- a/lib/binaries/Runtime4Docker.js +++ b/lib/binaries/Runtime4Docker.js @@ -17,6 +17,7 @@ commander.version(pkg.version) .description('pm2-runtime is a drop-in replacement Node.js binary for containers') .option('-i --instances ', 'launch [number] of processes automatically load-balanced. Increase overall performances and performance stability.') .option('--secret [key]', '[MONITORING] PM2 plus secret key') + .option('--no-autostart', 'add an app without automatic start') .option('--no-autorestart', 'start an app without automatic restart') .option('--stop-exit-codes ', 'specify a list of exit codes that should skip automatic restart') .option('--node-args ', 'space delimited arguments to pass to node in cluster mode - e.g. --node-args="--debug=7001 --trace-deprecation"') diff --git a/types/index.d.ts b/types/index.d.ts index 5b98aa28a..ab61446d3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -305,6 +305,10 @@ interface Pm2Env { } export interface StartOptions { + /** + * Enable or disable auto start after process added (default: true). + */ + autostart?: boolean; /** * Enable or disable auto restart after process failure (default: true). */ @@ -446,7 +450,7 @@ export interface StartOptions { interface ReloadOptions { /** - * (Default: false) If true is passed in, pm2 will reload it’s environment from process.env + * (Default: false) If true is passed in, pm2 will reload it’s environment from process.env * before reloading your process. */ updateEnv?: boolean;