How to use the forever.pidFilePath function in forever

To help you get started, we’ve selected a few forever 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 jiem / start-stop-daemon / index.js View on Github external
function startDaemon(options) {  
  
  var monitor, outFD, errFD;  
  
  options.uid = options.uid || crypto.randomBytes(3).toString('base64').replace(/[\+\/]/g, '_');
  options.logFile = forever.logFilePath(options.logFile || options.uid + '.log');
  options.pidFile = forever.pidFilePath(options.pidFile || options.uid + '.pid');
  options.options = process.argv;
  
  outFD = fs.openSync(options.logFile, 'a');
  errFD = fs.openSync(options.logFile, 'a');
  
  process.argv[2] = 'run';
  process.argv.splice(0, 2);

  monitor = child_process.spawn(process.execPath, [MONITOR_PATH, SCRIPT_PATH], {
    stdio: ['ipc', outFD, errFD],
    detached: true
  });
  monitor.on('exit', function (code) {
    console.error('Monitor died unexpectedly with exit code %d', code);
  });
  monitor.send(JSON.stringify(options));

forever

A simple CLI tool for ensuring that a given node script runs continuously (i.e. forever)

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis