How to use the pm2.start 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 schahriar / Galleon / bin / tasks / start.js View on Github external
isPortTaken(25, function (error, available) {
        if (error || !available) {
          console.log("PORT 25 is not available", "\nTRY", "authbind --deep galleon start".magenta, "\nFind More info about authbind -> https://github.com/schahriar/Galleon/blob/master/tutorials/AUTHBIND.md")
          process.exit(0);
        }

        // Start a script on the current folder
        /* BADPATCH -- There are significant issues with providing PM2 with a local script (https://github.com/schahriar/Galleon/issues/2). Start.JS should implement fallback methods and use a launch script inside the .galleon folder by default.  */
        pm2.start(path.resolve(__dirname, '../galleon.js'), { name: 'galleon-instance', force: true, scriptArgs: process.argv, nodeArgs: "--max_old_space_size=300" }, function (err, proc) {
          if (err) return new Error(err);

          // Get all processes running
          pm2.list(function (err, process_list) {
            console.log("Process Started".green);
            console.log("Type".cyan + " galleon status ".bold + "to show process status".cyan);

            // Disconnect to PM2
            pm2.disconnect(function () { process.exit(0) });
          });
        });
      })
    })
github mockstarjs / mockstar / packages / mockstar-cli / biz / local-server / run-by-pm2.js View on Github external
pm2.delete(name, function (err, apps) {
                    if (err) {
                        pm2.disconnect();   // Disconnects from PM2
                        throw err;
                    }

                    // 启动
                    pm2.start(pm2ConfigFilePath, function (err, apps) {
                        console.log('Start local server success!');
                        pm2.disconnect();   // Disconnects from PM2

                        if (err) {
                            throw err;
                        }
                    });
                });
            } else {
github odota / core / index.js View on Github external
async.each(apps, (app, cb) => {
      if (group === app.group) {
        console.log(app.script, app.instances);
        pm2.start(app.script, {
          instances: app.instances,
          restartDelay: 10000,
        }, (err) => {
          if (err) {
            // Log the error and continue
            console.error(err);
          }
          cb();
        });
      }
    }, (err) => {
      if (err) {
github adonisjs / adonis-commands / src / Server / Start.js View on Github external
pm2.connect(function () {
      pm2.start(pm2Options, function (err, apps) {
        /**
         * show error if there's one
         */
        if (err) {
          self.ansi.error(err.msg)
        } else {
          /**
           * print success message saying running process
           */
          console.log(`Started adonis process ${processName}`, self.ansi.icon('success'))
        }
        pm2.disconnect()

      })
    })
github tes / bosco / src / RunWrappers / Node.js View on Github external
self.getInterpreter(this.bosco, options, function (err, interpreter) {
    if (err) { return next(err); }

    if (interpreter) {
      if (!self.bosco.exists(interpreter)) {
        self.bosco.warn('Unable to locate node version requested: ' + interpreter.cyan + '.  Reverting to default.');
      } else {
        startOptions.interpreter = interpreter;
        self.bosco.log('Starting ' + options.name.cyan + ' via ' + interpreter + ' ...');
      }
    } else {
      self.bosco.log('Starting ' + options.name.cyan);
    }

    pm2.start(location, startOptions, next);
  });
};
github 1956-studio / wechat-ship / client / controllers / server.js View on Github external
server.startup = function(startPort, num, cb) {
	if (typeof startPort != "number") {
		throw "arg: startPort is not number";
	}
	num = num || os.cpus().length;
	for (var i = 0; i < num; i++, startPort++) {
		pm2.start(config.workdir + '/server.json', {
			name: 'server:' + startPort,
			scriptArgs: [startPort.toString()],
		}, function(err, proc) {
			if (err) {
				log.applog('error', 'pm2 start faild: ' + err);
			}
			if(cb && typeof cb == 'function') {
				cb(err);
			}
		});
	}
}
github TrueCar / gluestick / packages / gluestick / src / commands / start-server / runWithPM2.js View on Github external
setTimeout((): void => {
    pm2.start(pm2Config, (error: string) => {
      if (error) {
        logger.error(error);
        pm2.disconnect();
        logProcess.kill();
      }
      logger.success(`PM2 process ${name} started.`);
    });
  }, 1000);
github deanshub / web-pm2 / common / pm2wrapper.js View on Github external
pm2.connect(true,(err)=>{
        if(err) return reject(err);
        pm2.start(id, (err, details)=>{
          pm2.disconnect();
          if(err){
            return reject(err);
          }
          return resolve(details);
        });
      });
    });
github yyx990803 / pod / lib / api.js View on Github external
Client.executeRemote('getMonitorData', {}, function (err, list) {
            if (err) return callback(err)
            var runningProcs = findInList(appname, list)
            if (!runningProcs) {
                debug('attempting to start app...')
                pm2.start(prepareConfig(app), function (err) {
                    if (err) return callback(err)
                    return callback(null, appname.yellow + ' running on ' + (app.port || 'unknown port'))
                })
            } else {
                return abort(ERRORS.RUNNING, callback, { appname: appname });
            }
        });
    })