| 1099 | }); |
| 1100 | |
| 1101 | function startApps(app_name_to_start, cb) { |
| 1102 | var apps_to_start = []; |
| 1103 | var apps_started = []; |
| 1104 | var apps_errored = []; |
| 1105 | |
| 1106 | appConf.forEach(function(app, i) { |
| 1107 | if (app_name_to_start.indexOf(app.name) != -1) { |
| 1108 | apps_to_start.push(appConf[i]); |
| 1109 | } |
| 1110 | }); |
| 1111 | |
| 1112 | eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) { |
| 1113 | if (opts.cwd) |
| 1114 | app.cwd = opts.cwd; |
| 1115 | if (opts.force_name) |
| 1116 | app.name = opts.force_name; |
| 1117 | if (opts.started_as_module) |
| 1118 | app.pmx_module = true; |
| 1119 | |
| 1120 | var resolved_paths = null; |
| 1121 | |
| 1122 | // hardcode script name to use `serve` feature inside a process file |
| 1123 | if (app.script === 'serve') { |
| 1124 | app.script = path.resolve(__dirname, 'API', 'Serve.js') |
| 1125 | } |
| 1126 | |
| 1127 | try { |
| 1128 | resolved_paths = Common.resolveAppAttributes({ |
| 1129 | cwd : that.cwd, |
| 1130 | pm2_home : that.pm2_home |
| 1131 | }, app); |
| 1132 | } catch (e) { |
| 1133 | apps_errored.push(e) |
| 1134 | Common.err(`Error: ${e.message}`) |
| 1135 | return next(); |
| 1136 | } |
| 1137 | |
| 1138 | if (!resolved_paths.env) resolved_paths.env = {}; |
| 1139 | |
| 1140 | // Set PM2 HOME in case of child process using PM2 API |
| 1141 | resolved_paths.env['PM2_HOME'] = that.pm2_home; |
| 1142 | |
| 1143 | var additional_env = Modularizer.getAdditionalConf(resolved_paths.name); |
| 1144 | Object.assign(resolved_paths.env, additional_env); |
| 1145 | |
| 1146 | resolved_paths.env = Common.mergeEnvironmentVariables(resolved_paths, opts.env, deployConf); |
| 1147 | |
| 1148 | delete resolved_paths.env.current_conf; |
| 1149 | |
| 1150 | // Is KM linked? |
| 1151 | resolved_paths.km_link = that.gl_is_km_linked; |
| 1152 | |
| 1153 | if (resolved_paths.wait_ready) { |
| 1154 | Common.warn(`App ${resolved_paths.name} has option 'wait_ready' set, waiting for app to be ready...`) |
| 1155 | } |
| 1156 | that.Client.executeRemote('prepare', resolved_paths, function(err, data) { |
| 1157 | if (err) { |
| 1158 | Common.printError(conf.PREFIX_MSG_ERR + 'Process failed to launch %s', err.message ? err.message : err); |