How to use the pm2.describe 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 mockstarjs / mockstar / packages / mockstar-cli / biz / local-server / run-by-pm2.js View on Github external
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

                    if (err) {
                        throw err;
                    }
                });
            } else {
github feup-infolab / dendro / src / controllers / admin.js View on Github external
pm2.connect(function (err)
                    {
                        if (err)
                        {
                            console.error(err);
                            process.exit(2);
                        }

                        pm2.describe(Config.pm2AppName, function (err, description)
                        {
                            if (!err)
                            {
                                cb(null, description);
                            }
                            else
                            {
                                res.status(500).json({
                                    result: "error",
                                    message: "Error updating configuration!",
                                    error: err
                                });
                            }
                        });
                    });
                }
github oowl / pm2-webhook / lib / webhook.js View on Github external
function (callback) {
            if (!current_app.pre_hook) return callback(null);

            pm2.describe(name, function (err, apps) {
                if (err || !apps || apps.length === 0) return callback(err || new Error('Application not found'));

                var cwd = apps[0].pm_cwd ? apps[0].pm_cwd : apps[0].pm2_env.pm_cwd;

                exec(current_app.pre_hook, { cwd: cwd }, function (err, stdout, stderr) {
                    if (err) return callback(err);

                    console.log('Pre-hook command has been successfully executed for app %s', name);
                    return callback(null);
                });

                return callback(null);
            })
        },
github Alethio / ethstats-cli / lib / app-daemon.js View on Github external
if (daemonOption === 'stop') {
    pm2.stop(processOptions.name, error => {
      console.log(`Ethstats daemon STOP ${(error) ? chalk.red(`[FAILED] ${error.message}`) : chalk.green('[OK]')}`);
      pm2.disconnect();
    });
  }

  if (daemonOption === 'restart') {
    pm2.restart(processOptions.name, error => {
      console.log(`Ethstats daemon RESTART ${(error) ? chalk.red(`[FAILED] ${error.message}`) : chalk.green('[OK]')}`);
      pm2.disconnect();
    });
  }

  if (daemonOption === 'status') {
    pm2.describe(processOptions.name, (error, arr) => {
      arr.forEach(app => {
        let uptime = (app.pm2_env.status === 'stopped') ? 0 : moment.duration(Date.now() - app.pm2_env.created_at).humanize();

        console.log(`Name: ${app.name}`);
        console.log(`PID: ${app.pid}`);
        console.log(`Status: ${app.pm2_env.status}`);
        console.log(`Uptime: ${uptime}`);
        console.log(`Autorestart: ${app.pm2_env.autorestart}`);
        console.log(`Restart times: ${app.pm2_env.restart_time}`);
        console.log(`Instances: ${app.pm2_env.instances}`);
        console.log(`CPU usage: ${app.monit.cpu}`);
        console.log(`MEM usage: ${app.monit.memory}`);
      });
      pm2.disconnect();
    });
  }
github tes / bosco / commands / tail.js View on Github external
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;
            }
            bosco.log('Tailing ' + file);
            var tail = new Tail(file);

            tail.on('line', function (data) {
              bosco.console.log(repo + ' ' + data);
            });

            tail.on('error', function (error) {
github adobe / athena / athena.js View on Github external
}, function(error, res) {
          if (error) {
            throw error;
          }

          pm2.flush(APP_NAME, (err) => {
            if (err) {
              throw err;
            }
          });

          pm2.describe(0, (err, proc) => {
            const logFile = proc[0].pm2_env.pm_out_log_path;

            if (fs.existsSync(logFile)) {
              fs.unlinkSync(logFile);
            }

            setTimeout(() => {
              if (fs.existsSync(logFile)) {
                log.info(fs.readFileSync(logFile, 'UTF-8'));
              }

              pm2.disconnect();
              process.exit(0);
            }, 1000);
          });
        });
github deanshub / web-pm2 / common / pm2wrapper.js View on Github external
pm2.connect(true,(err)=>{
        if(err) return reject(err);
        pm2.describe(id, (err, details)=>{
          pm2.disconnect();
          if(err){
            return reject(err);
          }
          return resolve(details);
        });
      });
    });
github taurusai / kungfu / app / shared / utils / processUtils.ts View on Github external
pm2Connect().then(() => {
            try{
                pm2.describe(name, (err: Error, res: object): void => {
                    if(err){
                        logger.error(err)
                        reject(err);
                        return;
                    }
                    resolve(res)
                })
            }catch(err){
                logger.error(err)
                reject(err)
            }
        }).catch(err => reject(err))
    })