Skip to content

Commit

Permalink
Adds id parameter as outlined in #461.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Gariety authored and indexzero committed Aug 1, 2014
1 parent 99ee565 commit 55141c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
33 changes: 29 additions & 4 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ function stopOrRestart(action, event, format, target) {
var procs = processes;

if (target !== undefined && target !== null) {
procs = forever.findByIndex(target, processes)
procs = forever.findById(target, processes)
|| forever.findByIndex(target, processes)
|| forever.findByScript(target, processes)
|| forever.findByUid(target, processes);
}
Expand All @@ -195,7 +196,7 @@ function stopOrRestart(action, event, format, target) {
if (err) {
emitter.emit('error', err);
}

emitter.emit(event, forever.format(format, procs));
});
}
Expand Down Expand Up @@ -251,7 +252,7 @@ forever.load = function (options) {
options.columns = options.columns || forever.config.get('columns');
if (!options.columns) {
options.columns = [
'uid', 'command', 'script', 'forever', 'pid', 'logfile', 'uptime'
'uid', 'command', 'script', 'forever', 'pid', 'id', 'logfile', 'uptime'
];
}

Expand Down Expand Up @@ -608,6 +609,24 @@ forever.tail = function (target, options, callback) {
});
};

//
// ### function findById (id, processes)
// #### @index {string} Index of the process to find.
// #### @processes {Array} Set of processes to find in.
// Finds the process with the specified index.
//
forever.findById = function (id, processes) {
if (!processes) return null;

var procs = processes.filter(function (p) {
return p.id == id;
});

if (procs.length === 0) procs = null;

return procs;
};

//
// ### function findByIndex (index, processes)
// #### @index {string} Index of the process to find.
Expand Down Expand Up @@ -670,7 +689,7 @@ forever.format = function (format, procs) {
columns = forever.config.get('columns'),
rows = [[' '].concat(columns)],
formatted;

function mapColumns(prefix, mapFn) {
return [prefix].concat(columns.map(mapFn));
}
Expand Down Expand Up @@ -871,6 +890,12 @@ forever.columns = {
return proc.uid;
}
},
id: {
color: 'white',
get: function (proc) {
return proc.id ? proc.id : '';
}
},
command: {
color: 'grey',
get: function (proc) {
Expand Down
9 changes: 4 additions & 5 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ var getOptions = cli.getOptions = function (file) {
[
'pidFile', 'logFile', 'errFile', 'watch', 'minUptime', 'append',
'silent', 'outFile', 'max', 'command', 'path', 'spinSleepTime',
'sourceDir', 'uid', 'watchDirectory', 'watchIgnore', 'killTree', 'killSignal'
'sourceDir', 'uid', 'watchDirectory', 'watchIgnore', 'killTree', 'killSignal',
'id'
].forEach(function (key) {
options[key] = app.config.get(key);
});
Expand Down Expand Up @@ -268,12 +269,11 @@ app.cmd(/stop (.+)/, cli.stop = function (file) {
var runner = forever.stop(file, true);

runner.on('stop', function (process) {
forever.log.info('Forever stopped process:');
forever.log.data(process);
forever.log.info('Forever stopped process:' + '\n' + process);
});

runner.on('error', function (err) {
forever.log.error('Forever cannot find process with index: ' + file);
forever.log.error('Forever cannot find process with id: ' + file);
process.exit(1);
});
});
Expand Down Expand Up @@ -573,4 +573,3 @@ cli.start = function () {
app.start();
});
};

0 comments on commit 55141c8

Please sign in to comment.