(CLI, opts, cb)
| 343 | } |
| 344 | |
| 345 | function StartModule(CLI, opts, cb) { |
| 346 | if (!opts.cmd && !opts.package) throw new Error('module package.json not defined'); |
| 347 | if (!opts.development_mode) opts.development_mode = false; |
| 348 | |
| 349 | var package_json = require(opts.cmd || opts.package); |
| 350 | |
| 351 | /** |
| 352 | * Script file detection |
| 353 | * 1- *apps* field (default pm2 json configuration) |
| 354 | * 2- *bin* field |
| 355 | * 3- *main* field |
| 356 | */ |
| 357 | if (!package_json.apps && !package_json.pm2) { |
| 358 | package_json.apps = {}; |
| 359 | |
| 360 | if (package_json.bin) { |
| 361 | var bin = Object.keys(package_json.bin)[0]; |
| 362 | package_json.apps.script = package_json.bin[bin]; |
| 363 | } |
| 364 | else if (package_json.main) { |
| 365 | package_json.apps.script = package_json.main; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | Common.extend(opts, { |
| 370 | cwd : opts.proc_path, |
| 371 | watch : opts.development_mode, |
| 372 | force_name : package_json.name, |
| 373 | started_as_module : true |
| 374 | }); |
| 375 | |
| 376 | // Start the module |
| 377 | CLI.start(package_json, opts, function(err, data) { |
| 378 | if (err) return cb(err); |
| 379 | |
| 380 | if (opts.safe) { |
| 381 | Common.printOut(cst.PREFIX_MSG_MOD + 'Monitoring module behavior for potential issue (5secs...)'); |
| 382 | |
| 383 | var time = typeof(opts.safe) == 'boolean' ? 3000 : parseInt(opts.safe); |
| 384 | return setTimeout(function() { |
| 385 | CLI.describe(package_json.name, function(err, apps) { |
| 386 | if (err || apps[0].pm2_env.restart_time > 2) { |
| 387 | return Rollback.revert(CLI, package_json.name, function() { |
| 388 | return cb(new Error('New Module is instable, restored to previous version')); |
| 389 | }); |
| 390 | } |
| 391 | return cb(null, data); |
| 392 | }); |
| 393 | }, time); |
| 394 | } |
| 395 | |
| 396 | return cb(null, data); |
| 397 | }); |
| 398 | }; |
| 399 | |
| 400 | |
| 401 |
no test coverage detected
searching dependent graphs…