Skip to content

Commit

Permalink
Merge pull request #5782 from ultimate-tester/development
Browse files Browse the repository at this point in the history
Added autostart parameter to optionally prevent immediately starting
  • Loading branch information
Unitech authored Apr 26, 2024
2 parents c23da2f + 935a880 commit f9d2d63
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions lib/API/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/God.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {};
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/binaries/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ commander.version(pkg.version)
.option('--watch-delay <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 <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
.option('--no-treekill', 'Only kill the main process, not detached children')
Expand Down
1 change: 1 addition & 0 deletions lib/binaries/DevCLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/binaries/Runtime4Docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ commander.version(pkg.version)
.description('pm2-runtime is a drop-in replacement Node.js binary for containers')
.option('-i --instances <number>', '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 <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
.option('--node-args <node_args>', 'space delimited arguments to pass to node in cluster mode - e.g. --node-args="--debug=7001 --trace-deprecation"')
Expand Down
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f9d2d63

Please sign in to comment.