Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/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);
}
dpanel.init().finally(function() {
forever.list(false, function(err, processes, a) {
var running = false;
if (processes) {
running = processes.some(function(process) {
return (process.file == '../api.js');
});
}
if (!running) {
var child = forever.startDaemon('../api.js', {
max: 3,
silent: true,
options: []
});
}
});
#!/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.');
});
function getDaemonMeta(cb) {
forever.list(false, function(err, list) {
if (list) {
for (var i = 0, meta; meta = list[i]; i++) {
if (meta.file === SCRIPT_PATH) {
cb(meta);
return;
}
}
}
cb(null);
});
}
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);
}
});
};
findInList();
var exitWhenComplete = function () {
forever.list(false, function (err, children) {
if (err) {
callback && callback('Failed to stop loadbalancer daemon at index ' + index + ' - ' + err);
} else if (++shutDownFailures > maxShutDownFailures) {
callback && callback('Failed to stop loadbalancer daemon');
} else {
var pidIsStillActive = false;
if (children) {
for (var i = 0; i < children.length; i++) {
if (children[i].pid == pid) {
pidIsStillActive = true;
break;
}
}
}
if (pidIsStillActive) {
setTimeout(exitWhenComplete, shutDownInterval);