How to use the pm2.connect function in pm2

To help you get started, we’ve selected a few pm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jeffallen6767 / chain / cli.js View on Github external
}
        console.log("server started...");
        
      });
      
      // set-up a message handler to process messages FROM slaves
      pm2.launchBus(function(err, bus) {
        bus.on('process:msg', messageFromServer);
        bus.on('log:out', function(data) {
          console.log(data.data);
        });
      });
    }
  };
  //pm2.connect(true, callback);
  pm2.connect(callback);

} else if (server === "stop") {
  // shutdown
  pm2.disconnect(function() {
    console.log("disconnected....");
    // kill the master controller and all slave miners
    pm2.killDaemon(function() {
      console.log("daemon killed....");
      process.exit(0);
    });
    // return control to the caller
    console.log("server shutdown...");
  });
} else {
  program.help();
  process.exit(0);
github mockstarjs / mockstar / packages / mockstar-cli / biz / local-server / run-by-pm2.js View on Github external
function deleteTask(name) {
    pm2.connect(function (err) {
        if (err) {
            console.error(err);
            process.exit(2);
        }

        pm2.describe(name, function (err, apps) {
            if (err) {
                pm2.disconnect();   // Disconnects from PM2
                throw err;
            }

            // 已存在的场景才需要删除
            if (apps.length && apps[0].name === name) {
                pm2.delete(name, function (err, apps) {
                    console.log('Stop local server success!');
                    pm2.disconnect();   // Disconnects from PM2
github cmux / koot / packages / koot / bin / dev.js View on Github external
const complete = () => {
        npmRunScript(`pm2 logs`);
        if (open) return opn(`http://localhost:${process.env.SERVER_PORT}/`);
    };

    // 遇到错误
    const encounterError = e => {
        const error = e instanceof Error ? e : new Error(e);
        exitHandler({ error: true });
        throw error;
    };

    // 连接 PM2
    // console.log('noDaemon', !global)
    try {
        pm2.connect(!global, async err => {
            if (err) {
                // console.error(err)
                process.exit(2);
            }

            // eslint-disable-next-line no-console
            console.log(
                `  ` +
                    chalk.yellowBright('[koot/build] ') +
                    __('build.build_start', {
                        type: chalk.cyanBright(__(`appType.${appType}`)),
                        stage: chalk.green('client'),
                        env: chalk.green('dev')
                    })
            );
github tes / bosco / commands / tail.js View on Github external
function cmd(bosco, args) {
  var repoPattern = bosco.options.repo;
  var repoRegex = new RegExp(repoPattern);

  // Connect or launch PM2
  pm2.connect(function (err) {
    if (err) {
      bosco.error(err);
      return;
    }

    function describeRunningServices(running) {
      async.map(running, function (repo, next) {
        if (repo.match(repoRegex)) {
          pm2.describe(repo, function (err, list) {
            if (err) {
              bosco.error(err);
              return;
            }
            var file = list[0].pm2_env.pm_out_log_path;
            if (args[0] === 'err') {
              file = list[0].pm2_env.pm_err_log_path;
github pankleks / pm2-health / Health.ts View on Github external
this.configChanged();

        // fetch web config (if set)
        if (this._config.webConfig && this._config.webConfig.url) {
            await this.fetchConfig();

            if (this._config.webConfig.fetchIntervalM > 0)
                setInterval(
                    () => {
                        this.fetchConfig();
                    },
                    this._config.webConfig.fetchIntervalM * 60 * 1000);
        }

        PM2.connect((ex) => {
            stopIfEx(ex);

            PM2.launchBus((ex, bus) => {
                stopIfEx(ex);

                bus.on("process:event", (data) => {
                    if (data.manually || !this.isAppIncluded(data.process.name))
                        return;

                    if (Array.isArray(this._config.events) && this._config.events.indexOf(data.event) === -1)
                        return;

                    this._notify.send({
                        subject: `${data.process.name}:${data.process.pm_id} - ${data.event}`,
                        body: `
                        <p>App: <b>${data.process.name}:${data.process.pm_id}</b></p>
github jeffallen6767 / chain / src / miner.js View on Github external
meta = {
                "new_pm2_instance":false,
                "pm2_home":"C:\\Users\\jeffa\\.pm2",
                "pub_socket_file":"\\\\.\\pipe\\pub.sock",
                "rpc_socket_file":"\\\\.\\pipe\\rpc.sock"
            }
            */
            pm2_meta_info = meta;
            // master control is online, start filling the cluster with slave miners
            startSlaves(startConfig);
          }
        };
      // if we're testing set the master controller to die automatically if/when the script ends
      if (startConfig.testing) {
        // non-daemon mode
        pm2.connect(true, callback);
      } else {
        // daemon mode is normal mode
        // the mining cluster stays online even if/when script dies
        // a restart will reconnect to anything still online
        pm2.connect(callback);
      }
    },
    // API - stop ( shutdown ) the mining cluster
github yasaricli / pmteor / imports / api / applications / server / hooks.js View on Github external
Applications.after.remove((userId, doc) => {

  // Applications all logs removed.
  Logs.remove({ 'process.name': doc.bundleId });

  // Notifications removed
  Notifications.remove({ applicationId: doc._id });

  // CONNECT AND DELETE APPLICATION
  pm2.connect((connect_err) => {
    pm2.delete(doc.bundleId, (delete_err) => {

      // CD BUNDLES DIR
      cd(BUNDLE_DIR);

      // REMOVE APPLICATON DIR AND BUNDLE FILE
      rm('-rf', [

        // DIR
        doc.bundleId,

        // TAR.GZ
        `${doc.bundleId}.tar.gz`
      ]);

      // DISCONNECT
github pankleks / pm2-health / Health.js View on Github external
async go() {
        Log_1.info(`pm2-health is on`);
        this.configChanged();
        // fetch web config (if set)
        if (this._config.webConfig &amp;&amp; this._config.webConfig.url) {
            await this.fetchConfig();
            if (this._config.webConfig.fetchIntervalM &gt; 0)
                setInterval(() =&gt; {
                    this.fetchConfig();
                }, this._config.webConfig.fetchIntervalM * 60 * 1000);
        }
        PM2.connect((ex) =&gt; {
            stopIfEx(ex);
            PM2.launchBus((ex, bus) =&gt; {
                stopIfEx(ex);
                bus.on("process:event", (data) =&gt; {
                    if (data.manually || !this.isAppIncluded(data.process.name))
                        return;
                    if (Array.isArray(this._config.events) &amp;&amp; this._config.events.indexOf(data.event) === -1)
                        return;
                    this._notify.send({
                        subject: `${data.process.name}:${data.process.pm_id} - ${data.event}`,
                        body: `
                        <p>App: <b>${data.process.name}:${data.process.pm_id}</b></p>
                        <p>Event: <b>${data.event}</b></p>
                        <pre>${JSON.stringify(data, undefined, 4)}</pre>`,
                        priority: "high",
                        attachements: LOGS.filter(e =&gt; this._config.addLogs === true &amp;&amp; data.process[e]).map(e =&gt; ({ filename: path_1.basename(data.process[e]), path: data.process[e] }))
github tes / bosco / src / RunWrappers / Node.js View on Github external
Runner.prototype.init = function (bosco, next) {
  this.bosco = bosco;
  pm2.connect(next);
};