How to use forever - 10 common examples

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 appnexus / sicksync / bin / remote.js View on Github external
/**
 *  Bootstrapper for remote-daemon.js
 *
 *  Triggered by first run of sicksync client, through ssh connection
 *  This file should only run on your devbox, (IE, in the data center).
 *  
 */

 console.log('starting daemon');

var forever = require('forever'),
    daemonFilePath = './sicksync-dev/lib/remote-daemon.js';

// TODO: change these files paths, right now they output to user's home location on remote server
// due to the fact that the process.cwd() is /home/cdopuch
var daemon = forever.startDaemon(
    daemonFilePath,
    {
        // NOTE: these log files are truncated on each new run
        // TODO: rotate the logs so we can save old logs
        'logFile': 'new-remote-daemon.log',
        'outFile': 'new-remote-daemon-stdout.log',
        'errFile': 'new-remote-daemon-stderr.log',
        'max': 1,
        'uid': 'remote-daemon'
    }
);
var server = forever.startServer(daemon);

// process.stdout.write('[remote.js] up and waiting');
console.log('[remote.js] up and waiting');
github appnexus / sicksync / bin / remote.js View on Github external
// TODO: change these files paths, right now they output to user's home location on remote server
// due to the fact that the process.cwd() is /home/cdopuch
var daemon = forever.startDaemon(
    daemonFilePath,
    {
        // NOTE: these log files are truncated on each new run
        // TODO: rotate the logs so we can save old logs
        'logFile': 'new-remote-daemon.log',
        'outFile': 'new-remote-daemon-stdout.log',
        'errFile': 'new-remote-daemon-stderr.log',
        'max': 1,
        'uid': 'remote-daemon'
    }
);
var server = forever.startServer(daemon);

// process.stdout.write('[remote.js] up and waiting');
console.log('[remote.js] up and waiting');
github webgme / webgme / nodeserver / src / server / StandaloneServer.js View on Github external
else{
                res.writeHead(200);
            }
            res.end(data);
        });
    }),
        project,
        io = require('socket.io').listen(http);
    clientsrcfolder = "/../client";

    io.set('log level', 1); // reduce logging
    http.listen(parameters.ServerPort);

    console.log('[OS]:'+os.platform());
    if(os.platform().indexOf('win') === -1 || os.platform() === 'darwin'){
        project = new (require('forever').Monitor) (require('path').join(__dirname,'GmeProject.js'),{'options':[parameters.ProjectPort,parameters.ProjectName,parameters.BranchName]});
        project.start();
    }
    else{
        project = require('child_process').spawn('cmd');
        project.stdout.on('data', function (data) {
            console.log('[P-stdout] ' + data);
            if(data.toString().indexOf("no more clients, quit") !== -1){
                console.log('[P-stdout] restarting project');
                project.stdin.write('node --debug GmeProject.js '+parameters.ProjectPort+" "+parameters.ProjectName+" "+parameters.BranchName+'\n');
            }
        });
        project.stderr.on('data', function (data) {
            console.log('[P-stderr] ' + data);
        });
        project.stdin.write('node --debug GmeProject.js '+parameters.ProjectPort+" "+parameters.ProjectName+" "+parameters.BranchName+'\n');
    }
github webgme / webgme / nodeserver / src / server / standalon3.js View on Github external
}
                else{
                    res.writeHead(200);
                }
                res.end(data);
            });
        }),
        project,
        io = require('socket.io').listen(http);
        clientsrcfolder = "/../client";

    io.set('log level', 1); // reduce logging
    http.listen(parameters.ServerPort);
    if(os.platform().indexOf('win') === -1){
        project = new (require('forever').Monitor) (require('path').join(__dirname,'proj3ct.js'),{'options':[parameters.ProjectPort,parameters.ProjectName,parameters.BranchName]});
        project.start();
    }
    else{
        project = require('child_process').spawn('cmd');
        project.stdout.on('data', function (data) {
            console.log('[P-stdout] ' + data);
            if(data.toString().indexOf("no more clients, quit") !== -1){
                console.log('[P-stdout] restarting project');
                project.stdin.write('node --debug proj3ct.js '+parameters.ProjectPort+" "+parameters.ProjectName+" "+parameters.BranchName+'\n');
            }
        });
        project.stderr.on('data', function (data) {
            console.log('[P-stderr] ' + data);
        });
        project.stdin.write('node --debug proj3ct.js '+parameters.ProjectPort+" "+parameters.ProjectName+" "+parameters.BranchName+'\n');
    }
github SocketCluster / loadbalancer / bin / cli.js View on Github external
getBalancerIndices(function (err, balancers) {
    if (err) {
      callback && callback('Failed to stop loadbalancer daemons - ' + err);
    } else {
      for (var i = 0; i < balancers.length; i++) {
        forever.stop(balancers[i]);
      }
      var maxShutDownFailures = 20;
      var shutDownFailures = 0;
      var shutDownInterval = 500;
      
      var exitWhenComplete = function () {
        // Only terminate current daemon when all balancers 
        // have been killed.
        getBalancerIndices(function (err, activeBalancers) {
          if (err) {
            callback && callback('Failed to stop loadbalancer daemon - ' + err);
          } else if (++shutDownFailures > maxShutDownFailures) {
            callback && callback('Failed to stop loadbalancer daemon');
          } else {
            if (activeBalancers.length) {
              setTimeout(exitWhenComplete, shutDownInterval);
github avikj / fbash / src / fbash-start.js View on Github external
#!/usr/bin/env node

// if appstate has not already been saved,
// prompts user for credentials and saves appstate
// runs fbash as a daemon using forever

var forever = require('forever');
var readlineSync = require('readline-sync');
var fs = require('fs');
var login = require('facebook-chat-api');
var path = require('path');
var homedir = require('homedir')();

// if fbash processes are already running, stop them
forever.list(false, function(err, data) {
  if (err) throw err;
  if (data == null) return;
  for (var i = 0; i < data.length; i++) {
    if (data[i].uid === 'fbash'){
      forever.stop(i);
    }
  }
});

var fbashDir = path.join(homedir, '.fbash');

// ensures that the .fbash/ directory exists in the correct location
if (!fs.existsSync(fbashDir)) {
  fs.mkdirSync(fbashDir);
}
github azer / lowkick / test / server.js View on Github external
report.reset(function(error){

    if(error){
      logging.error('Failed to reset report document.');
      logging.error(error);

      return;
    }
  
    serverProcess = forever.start(['./bin/lowkick', 'publish', 'test/tmp-config.json'], {
      silent: true
    });

    serverProcess.on('start', function(process, data){

      var url = 'http://' + configdoc.server.host + ':' + configdoc.server.port,
          startTS = +(new Date);

      (function waitServerToStart(){
        
        request.get(url, function(error){

          if(error && +(new Date)-startTS
github geekuillaume / ChatUp / entrypoint.js View on Github external
forever.stopAll();
    process.exit(1);
  });

  if (process.argv[3] === "--use-container-ip") {
    require('dns').lookup(require('os').hostname(), function (err, addr, fam) {
      forever.start('examples/chatWorker/index.js', {
        silent: false,
        max: 1,
        env: {
          CHATUP_HOSTNAME: addr
        }
      });
    })
  } else {
    var workerDaemon = forever.start('examples/chatWorker/index.js', {
      silent: false,
      max: 1
    });
  }

  process.on('exit', function() {
    forever.stopAll();
  });

} else {
  console.error('First arg should be "dispatcher" or "worker"');
  console.error("Got:", process.argv);
  process.exit(1);
}
github lazojs / lazo / run.js View on Github external
function stop() {
    var forever = require('forever'),
        fsx = require('fs-extra');

    console.log('Stopping Lazo!...');
    if (fsx.existsSync(lazoPath + '/lazo.pid')) {
        try {
            forever.stop('lib/server/app.js', true);
            forever.cleanUp();
            fsx.remove(lazoPath + '/lazo.pid');
            console.log('Lazo! stopped');
        } catch (err) {
            console.log('Error stopping Lazo!');
            process.exit(1);
        }
    }
}
github lazojs / lazo / run.js View on Github external
function stop() {
    var forever = require('forever'),
        fsx = require('fs-extra');

    console.log('Stopping Lazo!...');
    if (fsx.existsSync(lazoPath + '/lazo.pid')) {
        try {
            forever.stop('lib/server/app.js', true);
            forever.cleanUp();
            fsx.remove(lazoPath + '/lazo.pid');
            console.log('Lazo! stopped');
        } catch (err) {
            console.log('Error stopping Lazo!');
            process.exit(1);
        }
    }
}

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

53 / 100
Full package analysis