* Method to START / RESTART a script * * @private * @param {string} script script name (will be resolved according to location)
(script, opts, cb)
| 667 | * @param {string} script script name (will be resolved according to location) |
| 668 | */ |
| 669 | _startScript (script, opts, cb) { |
| 670 | if (typeof opts == "function") { |
| 671 | cb = opts; |
| 672 | opts = {}; |
| 673 | } |
| 674 | var that = this; |
| 675 | |
| 676 | /** |
| 677 | * Commander.js tricks |
| 678 | */ |
| 679 | var app_conf = Config.filterOptions(opts); |
| 680 | var appConf = {}; |
| 681 | |
| 682 | if (typeof app_conf.name == 'function') |
| 683 | delete app_conf.name; |
| 684 | |
| 685 | delete app_conf.args; |
| 686 | |
| 687 | // Retrieve arguments via -- <args> |
| 688 | var argsIndex; |
| 689 | |
| 690 | if (opts.rawArgs && (argsIndex = opts.rawArgs.indexOf('--')) >= 0) |
| 691 | app_conf.args = opts.rawArgs.slice(argsIndex + 1); |
| 692 | else if (opts.scriptArgs) |
| 693 | app_conf.args = opts.scriptArgs; |
| 694 | |
| 695 | app_conf.script = script; |
| 696 | if(!app_conf.namespace) |
| 697 | app_conf.namespace = 'default'; |
| 698 | |
| 699 | if ((appConf = Common.verifyConfs(app_conf)) instanceof Error) { |
| 700 | Common.err(appConf) |
| 701 | return cb ? cb(Common.retErr(appConf)) : that.exitCli(conf.ERROR_EXIT); |
| 702 | } |
| 703 | |
| 704 | app_conf = appConf[0]; |
| 705 | |
| 706 | if (opts.watchDelay) { |
| 707 | if (typeof opts.watchDelay === "string" && opts.watchDelay.indexOf("ms") !== -1) |
| 708 | app_conf.watch_delay = parseInt(opts.watchDelay); |
| 709 | else { |
| 710 | app_conf.watch_delay = parseFloat(opts.watchDelay) * 1000; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | var mas = []; |
| 715 | if(typeof opts.ext != 'undefined') |
| 716 | hf.make_available_extension(opts, mas); // for -e flag |
| 717 | mas.length > 0 ? app_conf.ignore_watch = mas : 0; |
| 718 | |
| 719 | /** |
| 720 | * If -w option, write configuration to configuration.json file |
| 721 | */ |
| 722 | if (app_conf.write) { |
| 723 | var dst_path = path.join(process.env.PWD || process.cwd(), app_conf.name + '-pm2.json'); |
| 724 | Common.printOut(conf.PREFIX_MSG + 'Writing configuration to', chalk.blue(dst_path)); |
| 725 | // pretty JSON |
| 726 | try { |