Exemple #1
0
exports.getInstances = function(req, res){
    if (req.params.uid){

        var uid = req.params.uid;
        switch (uid){
            case "instances":
                forever.list("", function(err,proc){
                    var i = 0;

                    if(proc){
                        proc.forEach(function(){
                            var iDate = moment.duration(moment()-proc[i].ctime);
                            proc[i].uptime = iDate._data;
                            i++;
                        })
                        res.json(proc);
                    }
                    else {
                        res.json({'error':'No Unuts'});
                    }


                });
                break;
            default :
                forever.list("", function(err, proc) {
                    var i=-1;
                    while (proc[++i]) {
                        if (proc[i].uid === uid){
                            var iResp = proc[i];
                            var logfile = fs.readFile(iResp.logFile, 'utf-8', function (err, data) {
                                iResp.logContent = data.split('\n');
                                //console.log(iResp)
                                res.json(iResp);


                            });

                        }
                    };
                });
                break;
        }


    }


}
Exemple #2
0
function renderPage(req, res, processes) {  
    forever.list(false, function (p, procs) {
	var taskList = {};

	if (procs) {
            for (var i = 0;  i < procs.length;  ++i) {
    	    	var proc = procs[i];
	    	
	    	if (processes[proc.uid]) {
		    taskList[proc.uid] = {config: processes[proc.uid], proc: proc, started: moment(proc.ctime).format(),
                                          uptime: moment(proc.ctime).fromNow(true)};
	    	}
	    }
	}

	for (var p in processes) {
	    if (taskList[p] == null) {
		taskList[p] = {config: processes[p]};
	    }
	}
    
   	res.render('index', {
	    title : 'VLER DAS Console',
	    taskList : taskList 
    	});
    });
}
Exemple #3
0
exports.getUnit = function(req, res){
    if (req.params.uid){
        var uid = req.params.uid;
        switch (uid){
            case "units":
                iDb.all(function(err, units){
                    if(!err){
                        if(units != undefined){
                            res.json(units)
                        } else {
                            res.json({'error':'No units!'});
                        }
                    } else {
                        res.json({'error':'No units!'});
                    }
                });
                break;
            default :
                forever.list("", function(err, proc) {
                    var i=-1;
                    while (proc[++i]) {
                        if (proc[i].uid === uid){
                            var iResp = proc[i];
                            var logfile = fs.readFile(iResp.logFile, 'utf-8', function (err, data) {
                                iResp.logContent = data.split('\n');
                                //console.log(iResp)
                                res.json(iResp);
                            });
                        }
                    };
                });
                break;
        }
    }
}
Exemple #4
0
    var interval = setInterval(function () {
      process.stdout.write('.');

      forever.list(false, function (err, processes) {
        if (!tryingToStop && _.isArray(processes)) {
          // @FIXME Handle error if stopping when mockify is not started
          forever.stopAll().on('stopAll', function () {
            // @FIXME Handle forever errors
            deferred.resolve('Mockify daemon has been stopped.');
          });

          tryingToStop = true;
        }

        var allKilled = false;
        _.forEach(processes, function (process) {
          allKilled = allKilled && !isRunning(process.pid);
        });

        if (allKilled) {
          deferred.resolve(message);
        }
      });

      if (attempts > 5) {
        clearInterval(interval);
        deferred.resolve(message);
      }

      attempts++;
    }, 500);
Exemple #5
0
	func: function(user, userID, channel, args, message, bot){
		if(args.length < 2){
			return false;
		}
        //if(userID === "U1DNDKZDW" || userID === "U232Q4WQJ"){
        //    bot.sendMessage({
        //    	to: channel,
        //    	message: "lol no"
        //    });
        //    return true;
        //}
		if(args[1] === "list"){
		    var now = new Date().getTime();
			forever.list(false, function(err, info){
				var output = "\n*RUNNING FOREVER PROGRAMS:*\n";
				for(var i in info){
					var program = info[i];
					output += `${nums[i]} ${program.running ? ":white_check_mark:" : ":negative_squared_cross_mark: "} *${program.uid}* - ${prettySeconds((now - program.ctime)/1000)} - *${program.restarts} restarts*\n`;
					//output += ("["+i+"] *"+(program.uid)+"*: "+(program.running ? "RUNNING" : "STOPPED")+" ("+program.restarts+" restarts"+")\n")

				}
	        	bot.sendMessage({
		            to: channel,
		            message: output
		        });
	   		});
		}else if(args[1] === "restart"){
			if(args.length < 3)return false;
			try {
				bot.sendMessage({
					to: channel,
					message: "Restarting..."
				});
				forever.restart(args[2], true);
			}catch(e){
				bot.sendMessage({
					to: channel,
					message: e
				});
			}
		}else if(args[1] === "logs"){
			if(args.length < 3)return false;
		    var logText = "```";
		    forever.tail(args[2],{length: 40, stream: false} ,function(err, logs){
		        if(err)
		        	logText = err;
		        else
		        	logText += logs.line+"\n";
		    });
		    setTimeout(function(){
		    	bot.sendMessage({
		            to: channel,
		            message: logText+"```"
		        });
		    }, 500);
		}else{
			return false;
		}
        return true;
	},
Exemple #6
0
    get: function (request, response) {
        forever.list(false, function(err, results) {

            response.writeHeader(200, {"Content-Type": 'text/plain'});
            response.write(JSON.stringify(results));
            response.end();

        });
    }
Exemple #7
0
    forever.startServer(function () {
      forever.list(false, function (err, processes) {
        for (var index = 0; index < processes.length; index++) {
          if (processes[index].sourceDir === rootDir) {
            forever.stop(index);
          }
        }

        if (done && typeof done === 'function') done();
      });
    });
Exemple #8
0
 var findInList = function() {
   clearTimeout(timeout);
   forever.list(false, function(context, list) {
     var process = _.find(list, {file:script});
     if(process) {
       callback();
     }
     else {
       timeout = setTimeout(findInList, 500);
     }
   });
 };
Exemple #9
0
 .action(function() {
     forever.list(null, function(err, processes) {
         if (err) {
             throw err;
         }
         var process = _.findWhere(processes, { file: SERVER_PATH });
         if (!process) {
             return console.log('No octoppi server is running.');
         }
         forever.stop(_.indexOf(processes, process));
     });
 });
Exemple #10
0
    forever.startServer(function () {
      forever.list(false, function (err, processes) {
        var processCount = processes ? processes.length : 0;

        for (var index = 0; index < processCount; index++) {
          if (processes[index].sourceDir === rootDir) {
            console.log('nodeftpd (pid %s) is running...', processes[index].pid);
            process.exit();
          }
        }

        console.log('nodeftpd is stopped');
      });
    });
Exemple #11
0
function isProcessRunning(uid, callback) {
    var ret = false;
    forever.list(false, function (p, procs) {
        if (procs) {
	    for (var i = 0;  i < procs.length;  ++i) {
	        if (procs[i].uid == uid) {
		    ret = true;
		    break;
		}
	    }
	}
	callback(ret);
    });
}
Exemple #12
0
exports.stopDS = function (callback) {
    forever.list(false, function (err, processes) {
        if (err) {
            callback(err);
        } else if (!processes) {
            callback(null);
        } else {
            processes.forEach(function (proc, index) {
                if (proc.logFile === logFile) forever.stop(index);
            });
            callback(null);
        }
    });
};
Exemple #13
0
function stop() {
  forever.list(null, function (err, processes) {
    if (err) throw err;
    if ((processes || []).some(function (proc, index) {
      if (proc.uid === 'monploy_agent') {
        forever.stop(index);
        return true;
      } else {
        return false;
      }
    })) {
      setTimeout(stop, 1000);
    } else {
      console.log('stopped');
    }
  });
}
Exemple #14
0
function getServer (callback) {
  forever.list(false, function (err, data) {
    if (err) {
      console.log(err);
      process.exit(1);
    }

    for (var i in data) {
      if (~data[i].file.indexOf('crypton/server/bin/cli.js')) {
        data[i].index = i;
        return callback(data[i]);
      }
    }

    callback(null);
  });
}
Exemple #15
0
module.exports = function(command) {
  switch (command || 'start') {
    case 'start':
      startDaemon(path.join(__dirname, 'server.js'));
      startDaemon(path.join(__dirname, 'kafka.js'));
      break;
    case 'stop':
      forever.stop(args[2]);
      break;
    case 'list':
      forever.list(true, function(err, list) {
        console.log(list);
      });
      break;
    case 'stopall':
      forever.stopAll(true);
      break;
  }
};
/**
 * Locates running process previously started by forever based on index file, and notifies callback. Will notify of undefined if not found, other wise the unformatted process object.
 * @param  {String}   index    Index filename.
 * @param  {Function} callback Delegate method to invoke with either the found process object or undefined if not found.
 */
function findProcessWithIndex( index, callback ) {
  var i, process;
  try {
    forever.list(false, function(context, list) {
      i = list ? list.length : 0;
      while( --i > -1 ) {
        process = list[i];
        if( process.hasOwnProperty('file') &&
          process.file === index ) {
          break;
        }
        process = undefined;
      }
      callback.call(null, process);
    });
  }
  catch( e ) {
    error( 'Error in trying to find process ' + index + ' in forever. [REASON] :: ' + e.message );
    callback.call(null, undefined);
  }
}
Exemple #17
0
    runNextCommand(function() {
      // now let's parse .awsbox.config
      try {
        awsboxJson = JSON.parse(fs.readFileSync(path.join(newCodeDir, '.awsbox.json')));
        if (!awsboxJson.processes) throw "missing 'processes' property";
      } catch(e) {
        console.log("!! Couldn't read .awsbox.json: " + e.toString());
        process.exit(1);
      }

      // once all commands are run, we'll start servers with forever
      forever.list(false, function(err, l) {
        checkErr("while listing processes", err);
        if (!l || !l.length) return moveCode()
        else {
          var sa = forever.stopAll();
          console.log(">> stopping running servers");
          sa.on('stopAll', function() {
            moveCode();
          });
        }
      });
    });
Exemple #18
0
/**
 * Attempts to get list of processes
 */
function listOfProcess() {
  log( 'Attempting to get list of daemons.');

  done = this.async();
  var i, process;
  try {
    forever.list(false, function(context, list) {
      if (!list) {
        log( 'The list of processes in forever is empty.' );
        done();
      } else {
        i = list.length;
        while( --i > -1 ) {
          process = list[i];
          if ( process.hasOwnProperty('file') ) log( forever.format(true, [process]) );
        }
        done();
      }
    });
  }
  catch( e ) {
    error( 'Error in trying to get list in forever. [REASON] :: ' + e.message );
  }
}
Exemple #19
0
#!/usr/bin/env node
var forever = require('forever');

forever.list(false, function(err, data){
	if(data == null) return;
	for(var i = 0; i < data.length; i++){
		if(data[i].uid == 'fbash')
			forever.stop(i);
	}
	console.log('fbash stopped.');
});
Exemple #20
0
// 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);
}

// ensures that the settings.json file exists in the correct location
fs.stat(path.join(fbashDir, 'settings.json'), function(err, stat) { 
  if (err == null) return;
Exemple #21
0
var foreverize = function(options){
  // slog("foreverize before start_forever");

 if(process.env.SPAWNED_BY_FOREVER === "true"){
    // slog("I'm a forever subprocess");
    return foreverize;
  }

  // slog("I'm a forever MASTER");

  var mp = require('./lib/utils').mp;
  var config = require('./lib/config');

  // autodetect calling script
  var script_file = getCalleeFile();

  // local config (gets config file name from argv or default locations)
  var forever_config = config.load_config(options);

  if(forever_config.script){
    // console.log("switching script to:", forever_config.script);
    script_file = mp(forever_config.script);
  }

  process.chdir(path.dirname(script_file));
  // console.log("using script:", script_file);

  // update config with our own overrides
  forever_config.env = forever_config.env || {};
  forever_config.env.SPAWNED_BY_FOREVER =  "true";
  forever_config.options =  process.argv.slice(2); // pass on commandline args transparently

  forever_config = config.apply_defaults(forever_config);
  // slog("config:", util.inspect(forever_config));

  // slog("starting Monitor:", script_file);
  var start = function(){
    var monitor = new (forever.Monitor)(script_file, forever_config);

    monitor.on('exit', function(){
      console.error("Monitored " + script_file + " exited");
    });

    monitor.start();
    forever.startServer(monitor);
  };

  // make sure only one cluster process with this uid is running
  forever.list(null, function(err, processes){
    if(err){
      return console.error("Failed to get listing of forever processes:", err);
    } else if(processes && processes.forEach) {
      processes.forEach(function(p){
        if( p.uid === forever_config.uid ){
          throw new Error("A forever process with uid '" + p.uid +
                          "' is already running:\n" + util.inspect(p, null, 1));
        }
      });
    }

    start();
  });

  return foreverize;
};