Skip to content

Commit

Permalink
[fix] Create sockPath if it does not exist already. Fixes #92
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jul 23, 2011
1 parent 845ce2c commit e7b9e58
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
46 changes: 36 additions & 10 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var fs = require('fs'),
cliff = require('cliff'),
daemon = require('daemon'),
nconf = require('nconf'),
mkdirp = require('mkdirp').mkdirp,
portfinder = require('portfinder'),
timespan = require('timespan'),
winston = require('winston');
Expand Down Expand Up @@ -724,13 +725,8 @@ forever.columns = {
// Returns all data for processes managed by forever.
//
function getAllProcesses (callback) {
var results = [],
sockPath = forever.config.get('sockPath'),
sockets = fs.readdirSync(sockPath);

if (sockets.length === 0) {
return callback();
}
var sockPath = forever.config.get('sockPath'),
results = [];

function getProcess (name, next) {
var fullPath = path.join(sockPath, name),
Expand Down Expand Up @@ -761,11 +757,41 @@ function getAllProcesses (callback) {
socket.connect(fullPath);
}

async.forEach(sockets, getProcess, function () {
callback(results);
});
getSockets(sockPath, function (err, sockets) {
if (err || (sockets && sockets.length === 0)) {
return callback(err);
}

async.forEach(sockets, getProcess, function () {
callback(results);
});
})
};

//
// ### function getSockets (sockPath, callback)
// #### @sockPath {string} Path in which to look for UNIX domain sockets
// #### @callback {function} Continuation to pass control to when complete
// Attempts to read the files from `sockPath` if the directory does not exist,
// then it is created using `mkdirp`.
//
function getSockets (sockPath, callback) {
try {
var sockets = fs.readdirSync(sockPath);
}
catch (ex) {
if (ex.code !== 'ENOENT') {
return callback(ex);
}

return mkdirp(sockPath, 0755, function (err) {
return err ? callback(err) : callback(null, []);
});
}

callback(null, sockets);
}

//
// ### function getAllPids ()
// Returns the set of all pids managed by forever.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"cliff": "0.x.x",
"eyes": "0.1.x",
"daemon": "0.3.x",
"mkdirp": "0.x.x",
"nconf": "0.x.x",
"optimist": "0.2.x",
"pkginfo": "0.x.x",
Expand Down

0 comments on commit e7b9e58

Please sign in to comment.