mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
3 lines
2.9 KiB
JavaScript
3 lines
2.9 KiB
JavaScript
var gl_retry,commander=require("commander"),fs=require("fs"),path=require("path"),async=require("async"),debug=require("debug")("pm2:cli"),util=require("util"),chalk=require("chalk"),fclone=require("fclone"),IMMUTABLE_MSG=chalk.bold.blue("Use --update-env to update environment variables"),API=module.exports=function(e){e||(e={});var n=this;if(this.daemon_mode=void 0===e.daemon_mode||e.daemon_mode,this.pm2_home=conf.PM2_ROOT_PATH,this.public_key=process.env.KEYMETRICS_SECRET||e.public_key||null,this.secret_key=process.env.KEYMETRICS_PUBLIC||e.secret_key||null,this.machine_name=process.env.INSTANCE_NAME||e.machine_name||null,this.cwd=process.cwd(),e.cwd&&(this.cwd=path.resolve(e.cwd)),e.pm2_home&&1==e.independent)throw new Error("You cannot set a pm2_home and independent instance in same time");if(e.pm2_home)this.pm2_home=e.pm2_home,conf=util._extend(conf,path_structure(this.pm2_home));else if(1==e.independent&&!1===conf.IS_WINDOWS){var t=require("crypto").randomBytes(8).toString("hex");this.pm2_home=path.join("/tmp",t),void 0===e.daemon_mode&&(this.daemon_mode=!1),conf=util._extend(conf,path_structure(this.pm2_home))}this._conf=conf,conf.IS_WINDOWS&&process.stdout._handle&&process.stdout._handle.setBlocking&&process.stdout._handle.setBlocking(!0),this.Client=new Client({pm2_home:n.pm2_home,conf:this._conf,secret_key:this.secret_key,public_key:this.public_key,daemon_mode:this.daemon_mode,machine_name:this.machine_name}),this.gl_interact_infos=null,this.gl_is_km_linked=!1;try{var o=fs.readFileSync(conf.INTERACTOR_PID_PATH);o=parseInt(o.toString().trim()),process.kill(o,0),n.gl_is_km_linked=!0}catch(e){n.gl_is_km_linked=!1}this.secret_key&&"local_test"==process.env.NODE_ENV&&(n.gl_is_km_linked=!0),KMDaemon.getInteractInfo(this._conf,function(e,t){n.gl_interact_infos=t})};throw API.prototype.connect=function(e,n){var t=this;this.start_timer=new Date,void 0===n?(n=e,e=!1):!0===e&&(this.Client.daemon_mode=!1,this.daemon_mode=!1),this.Client.start(function(e,o){return e?n(e):0==o.new_pm2_instance&&!0===t.daemon_mode?n(e,o):void Modularizer.launchAll(t,function(t){return n(e,o)})})},API.prototype.destroy=function(e){var n=require("shelljs").exec,t=this;debug("Killing and deleting current deamon"),this.killDaemon(function(){var o="rm -rf "+t.pm2_home,i=path.join(t.pm2_home,"module_conf.json");path.join(t.pm2_home,"pm2.pid");return t.pm2_home.indexOf(".pm2")>-1?e(new Error("Destroy is not a allowed method on .pm2")):fs.accessSync?(fs.access(i,fs.R_OK,function(i){if(i)return e(i);debug("Deleting temporary folder %s",t.pm2_home),n(o,e)}),!1):void fs.exists(i,function(i){return i&&(debug("Deleting temporary folder %s",t.pm2_home),n(o,e)),e(null)})})},API.prototype.disconnect=API.prototype.close=function(e){var n=this;e||(e=function(){}),this.Client.close(function(t,o){return debug("The session lasted %ds",(new Date-n.start_timer)/1e3),e(t,o)})},API.prototype.launchModules=function(e){Modularizer.launchAll(this,e)},new Error("muhahahaha");
|
|
//# sourceMappingURL=API.min.js.map
|