* Main function to operate with PM2 daemon * * @param {String} action_name Name of action (restartProcessId, deleteProcessId, stopProcessId) * @param {String} process_name can be 'all', a id integer or process name * @param {Object} envs object with CLI options / environment
(action_name, process_name, envs, cb)
| 1301 | * @param {Object} envs object with CLI options / environment |
| 1302 | */ |
| 1303 | _operate (action_name, process_name, envs, cb) { |
| 1304 | var that = this; |
| 1305 | var update_env = false; |
| 1306 | var ret = []; |
| 1307 | |
| 1308 | // Make sure all options exist |
| 1309 | if (!envs) |
| 1310 | envs = {}; |
| 1311 | |
| 1312 | if (typeof(envs) == 'function'){ |
| 1313 | cb = envs; |
| 1314 | envs = {}; |
| 1315 | } |
| 1316 | |
| 1317 | // Set via env.update (JSON processing) |
| 1318 | if (envs.updateEnv === true) |
| 1319 | update_env = true; |
| 1320 | |
| 1321 | var concurrent_actions = envs.parallel || conf.CONCURRENT_ACTIONS; |
| 1322 | |
| 1323 | if (!process.env.PM2_JSON_PROCESSING || envs.commands) { |
| 1324 | envs = that._handleAttributeUpdate(envs); |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Set current updated configuration if not passed |
| 1329 | */ |
| 1330 | if (!envs.current_conf) { |
| 1331 | var _conf = fclone(envs); |
| 1332 | envs = { |
| 1333 | current_conf : _conf |
| 1334 | } |
| 1335 | |
| 1336 | // Is KM linked? |
| 1337 | envs.current_conf.km_link = that.gl_is_km_linked; |
| 1338 | } |
| 1339 | |
| 1340 | /** |
| 1341 | * Operate action on specific process id |
| 1342 | */ |
| 1343 | function processIds(ids, cb) { |
| 1344 | Common.printOut(conf.PREFIX_MSG + 'Applying action %s on app [%s](ids: %s)', action_name, process_name, ids); |
| 1345 | |
| 1346 | if (ids.length <= 2) |
| 1347 | concurrent_actions = 1; |
| 1348 | |
| 1349 | if (action_name == 'deleteProcessId') |
| 1350 | concurrent_actions = 10; |
| 1351 | |
| 1352 | eachLimit(ids, concurrent_actions, function(id, next) { |
| 1353 | var opts; |
| 1354 | |
| 1355 | // These functions need extra param to be passed |
| 1356 | if (action_name == 'restartProcessId' || |
| 1357 | action_name == 'reloadProcessId' || |
| 1358 | action_name == 'softReloadProcessId') { |
| 1359 | var new_env = {}; |
| 1360 |
no test coverage detected