| 973 | }); |
| 974 | |
| 975 | function startApps(app_name_to_start, cb) { |
| 976 | var apps_to_start = []; |
| 977 | var apps_started = []; |
| 978 | |
| 979 | appConf.forEach(function(app, i) { |
| 980 | if (app_name_to_start.indexOf(app.name) != -1) { |
| 981 | apps_to_start.push(appConf[i]); |
| 982 | } |
| 983 | }); |
| 984 | |
| 985 | eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) { |
| 986 | if (opts.cwd) |
| 987 | app.cwd = opts.cwd; |
| 988 | if (opts.force_name) |
| 989 | app.name = opts.force_name; |
| 990 | if (opts.started_as_module) |
| 991 | app.pmx_module = true; |
| 992 | |
| 993 | var resolved_paths = null; |
| 994 | |
| 995 | // hardcode script name to use `serve` feature inside a process file |
| 996 | if (app.script === 'serve') { |
| 997 | app.script = path.resolve(__dirname, 'API', 'Serve.js') |
| 998 | } |
| 999 | |
| 1000 | try { |
| 1001 | resolved_paths = Common.resolveAppAttributes({ |
| 1002 | cwd : that.cwd, |
| 1003 | pm2_home : that.pm2_home |
| 1004 | }, app); |
| 1005 | } catch (e) { |
| 1006 | return next(); |
| 1007 | } |
| 1008 | |
| 1009 | if (!resolved_paths.env) resolved_paths.env = {}; |
| 1010 | |
| 1011 | // Set PM2 HOME in case of child process using PM2 API |
| 1012 | resolved_paths.env['PM2_HOME'] = that.pm2_home; |
| 1013 | |
| 1014 | var additional_env = Modularizer.getAdditionalConf(resolved_paths.name); |
| 1015 | util._extend(resolved_paths.env, additional_env); |
| 1016 | |
| 1017 | resolved_paths.env = Common.mergeEnvironmentVariables(resolved_paths, opts.env, deployConf); |
| 1018 | |
| 1019 | delete resolved_paths.env.current_conf; |
| 1020 | |
| 1021 | // Is KM linked? |
| 1022 | resolved_paths.km_link = that.gl_is_km_linked; |
| 1023 | |
| 1024 | that.Client.executeRemote('prepare', resolved_paths, function(err, data) { |
| 1025 | if (err) { |
| 1026 | Common.printError(conf.PREFIX_MSG_ERR + 'Process failed to launch %s', err.message ? err.message : err); |
| 1027 | return next(); |
| 1028 | } |
| 1029 | if (data.length === 0) { |
| 1030 | Common.printError(conf.PREFIX_MSG_ERR + 'Process config loading failed', data); |
| 1031 | return next(); |
| 1032 | } |