Skip to content

Commit 935a880

Browse files
ultimate-testerjordi
authored andcommitted
Added autostart parameter to optionally prevent immediately starting applications
(cherry picked from commit b34498f)
1 parent c23da2f commit 935a880

File tree

8 files changed

+24
-3
lines changed

8 files changed

+24
-3
lines changed

lib/API.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,8 @@ class API {
16301630
delete appConf.vizion;
16311631
if (appConf.automation === true)
16321632
delete appConf.automation;
1633+
if (appConf.autostart === true)
1634+
delete appConf.autostart;
16331635
if (appConf.autorestart === true)
16341636
delete appConf.autorestart;
16351637

lib/API/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@
187187
"docDefault" : "True",
188188
"docDescription": "Enable or disable the versioning metadatas (vizion library)"
189189
},
190+
"autostart": {
191+
"type": "boolean",
192+
"default": true,
193+
"docDefault": "True",
194+
"docDescription": "Enable or disable auto start when adding process"
195+
},
190196
"autorestart": {
191197
"type": "boolean",
192198
"default": true,

lib/Common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ Common.safeExtend = function(origin, add){
565565
if (!add || typeof add != 'object') return origin;
566566

567567
//Ignore PM2's set environment variables from the nested env
568-
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'];
568+
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'];
569569

570570
var keys = Object.keys(add);
571571
var i = keys.length;

lib/God.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ God.executeApp = function executeApp(env, cb) {
168168

169169
Utility.extend(env_copy, env_copy.env);
170170

171-
env_copy['status'] = cst.LAUNCHING_STATUS;
171+
env_copy['status'] = env.autostart ? cst.LAUNCHING_STATUS : cst.STOPPED_STATUS;
172172
env_copy['pm_uptime'] = Date.now();
173173
env_copy['axm_actions'] = [];
174174
env_copy['axm_monitor'] = {};
@@ -211,6 +211,12 @@ God.executeApp = function executeApp(env, cb) {
211211

212212
God.registerCron(env_copy)
213213

214+
if(!env_copy['autostart']) {
215+
var clu = {pm2_env: env_copy, process: {pid: 0}};
216+
God.clusters_db[env_copy.pm_id] = clu;
217+
return cb(null, clu);
218+
}
219+
214220
/** Callback when application is launched */
215221
var readyCb = function ready(proc) {
216222
// If vizion enabled run versioning retrieval system

lib/binaries/CLI.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ commander.version(pkg.version)
7676
.option('--watch-delay <delay>', 'specify a restart delay after changing files (--watch-delay 4 (in sec) or 4000ms)')
7777
.option('--no-color', 'skip colors')
7878
.option('--no-vizion', 'start an app without vizion feature (versioning control)')
79+
.option('--no-autostart', 'add an app without automatic start')
7980
.option('--no-autorestart', 'start an app without automatic restart')
8081
.option('--stop-exit-codes <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
8182
.option('--no-treekill', 'Only kill the main process, not detached children')

lib/binaries/DevCLI.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function run(cmd, opts) {
6565
var timestamp = opts.timestamp;
6666

6767
opts.watch = true;
68+
opts.autostart = true;
6869
opts.autorestart = true;
6970
opts.restart_delay = 1000
7071
if (opts.autoExit)

lib/binaries/Runtime4Docker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ commander.version(pkg.version)
1717
.description('pm2-runtime is a drop-in replacement Node.js binary for containers')
1818
.option('-i --instances <number>', 'launch [number] of processes automatically load-balanced. Increase overall performances and performance stability.')
1919
.option('--secret [key]', '[MONITORING] PM2 plus secret key')
20+
.option('--no-autostart', 'add an app without automatic start')
2021
.option('--no-autorestart', 'start an app without automatic restart')
2122
.option('--stop-exit-codes <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
2223
.option('--node-args <node_args>', 'space delimited arguments to pass to node in cluster mode - e.g. --node-args="--debug=7001 --trace-deprecation"')

types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ interface Pm2Env {
305305
}
306306

307307
export interface StartOptions {
308+
/**
309+
* Enable or disable auto start after process added (default: true).
310+
*/
311+
autostart?: boolean;
308312
/**
309313
* Enable or disable auto restart after process failure (default: true).
310314
*/
@@ -446,7 +450,7 @@ export interface StartOptions {
446450

447451
interface ReloadOptions {
448452
/**
449-
* (Default: false) If true is passed in, pm2 will reload it’s environment from process.env
453+
* (Default: false) If true is passed in, pm2 will reload it’s environment from process.env
450454
* before reloading your process.
451455
*/
452456
updateEnv?: boolean;

0 commit comments

Comments
 (0)