Skip to content

Commit

Permalink
[minor] Trim whitespace in lib/*
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jul 11, 2011
1 parent 2a163d3 commit bc8153a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
50 changes: 22 additions & 28 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ forever.startDaemon = function (script, options) {
options.pidFile = forever.pidFilePath(options.pidFile || options.uid + '.pid');

var monitor = new forever.Monitor(script, options);

fs.open(options.logFile, options.appendLog ? 'a+' : 'w+', function (err, fd) {
if (err) {
return monitor.emit('error', err);
Expand Down Expand Up @@ -225,53 +225,47 @@ forever.startServer = function () {
current = getData(),
socket = path.join(forever.config.get('sockPath'), 'forever.sock'),
server;

function getData () {
return monitors.map(function (m) { return m.data });
}

function formatProc (proc) {
var info = [
proc.command,
proc.file,
':',
proc.uid
].join(' ');

return '[' + info + ']'
}

server = net.createServer(function (socket) {
//
// Write the specified data and close the socket
//
socket.end(JSON.stringify({ monitors: getData() }));
});

portfinder.getSocket({ path: socket }, function (err, socket) {
if (err) {
//
// TODO: This is really bad.
//
}
server.on('error', function () {

server.on('error', function () {
//
// TODO: This is really bad.
//
});

server.listen(socket, function () {
if (callback) {
callback(null, server, socket);
}
});

process.title = [
'forever',
current.map(function (p) { return formatProc(p) }),
socket
].join(' ');
});
});
};

Expand Down Expand Up @@ -405,14 +399,14 @@ forever.findByScript = function (script, processes) {
//
forever.stopAll = function (format) {
var emitter = new events.EventEmitter();

getAllProcesses(function (processes) {
var pids = getAllPids(processes);

if (format) {
processes = forever.format(format, processes);
}

if (pids && processes) {
var fPids = pids.map(function (pid) { return pid.foreverPid }),
cPids = pids.map(function (pid) { return pid.pid });
Expand All @@ -436,7 +430,7 @@ forever.stopAll = function (format) {
});
}
});

return emitter;
};

Expand All @@ -449,14 +443,14 @@ forever.stopAll = function (format) {
forever.list = function (format, callback) {
getAllProcesses(function (processes) {
callback(null, forever.format(format, processes));
});
});
};

forever.format = function (format, procs) {
if (!procs || procs.length === 0) {
return null;
}

if (format) {
var index = 0, rows = [
[' ', 'uid', 'command ', 'script', 'forever ', 'pid', 'logfile', 'uptime']
Expand Down Expand Up @@ -521,14 +515,14 @@ forever.cleanUp = function (cleanLogs, allowManager) {
//
// If we are cleaning logs then do so if the process
// has a logfile.
//
//
return fs.unlink(proc.logFile, function () {
done();
});
}

done();
});
});
}

function cleanProcess (proc, done) {
Expand Down Expand Up @@ -682,27 +676,27 @@ function getAllProcesses (callback) {
if (sockets.length === 0) {
return callback();
}

function getProcess (name, next) {
var fullPath = path.join(sockPath, name),
socket = new net.Socket({ type: 'unix' });

socket.on('error', function (err) {
if (err.code === 'ECONNREFUSED') {
try { fs.unlinkSync(fullPath) }
catch (ex) { }
return next();
}

next(err);
});

socket.on('data', function (data) {
var monitors = JSON.parse(data.toString());
results.push.apply(results, monitors.monitors);
next();
});

socket.connect(fullPath);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cli.exec = function (action, file, options) {
});
return;
}

if (file && action === 'start') {
forever.log.info('Forever processing file: ' + file.grey);
}
Expand Down Expand Up @@ -73,7 +73,7 @@ cli.start = function (file, options, daemon) {
var monitor = daemon
? forever.startDaemon(file, options)
: forever.start(file, options);

monitor.on('start', function () {
forever.startServer(monitor);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Monitor.prototype.trySpawn = function () {
};

//
// ### @data
// ### @data {Object}
// Responds with the appropriate information about
// this `Monitor` instance and it's associated child process.
//
Expand Down

0 comments on commit bc8153a

Please sign in to comment.