Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

forever

Package Overview
Dependencies
Maintainers
4
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forever - npm Package Compare versions

Comparing version 0.10.0 to 0.10.5

187

lib/forever.js

@@ -37,2 +37,11 @@ /*

//
// Setup `forever out` for logEvents with `winston` custom logger.
//
forever.out = new (winston.Logger)({
transports: [
new (winston.transports.Console)()
]
});
//
// ### Export Components / Settings

@@ -44,3 +53,3 @@ // Export `version` and important Prototypes from `lib/forever/*`

forever.checkProcess = require('forever-monitor').checkProcess;
forever.root = path.join(process.env.HOME || '/root', '.forever');
forever.root = path.join(process.env.HOME || process.env.USERPROFILE || '/root', '.forever');
forever.config = new nconf.File({ file: path.join(forever.root, 'config.json') });

@@ -72,3 +81,3 @@ forever.Forever = forever.Monitor = require('forever-monitor').Monitor;

var sockets;
try {

@@ -112,6 +121,6 @@ sockets = fs.readdirSync(sockPath);

});
socket.send(['data']);
});
socket.on('error', function (err) {

@@ -156,8 +165,7 @@ if (err.code === 'ECONNREFUSED') {

var emitter = new events.EventEmitter(),
results = [],
pids;
results = [];
function sendAction(proc, next) {
var socket = new nssocket.NsSocket();
socket.connect(proc.socket, function (err) {

@@ -172,6 +180,6 @@ if (err) {

});
socket.send([action]);
});
socket.on('error', function (err) {

@@ -183,3 +191,3 @@ next(err);

getAllProcesses(function (processes) {
var procs = processes;
var procs = processes;

@@ -197,3 +205,3 @@ if (target !== undefined && target !== null) {

}
emitter.emit(event, forever.format(format, procs));

@@ -223,2 +231,3 @@ });

options.loglength = options.loglength || 100;
options.logstream = options.logstream || false;
options.root = options.root || forever.root;

@@ -262,5 +271,11 @@ options.pidPath = options.pidPath || path.join(options.root, 'pids');

forever.config.set('loglength', options.loglength);
forever.config.set('logstream', options.logstream);
forever.config.set('columns', options.columns);
//
// Setup timestamp to event logger
//
forever.out.transports.console.timestamp = forever.config.get('timestamp') === 'true';
//
// Attempt to see if `forever` has been configured to

@@ -368,7 +383,7 @@ // run in debug mode.

}
if (!options.logFile) {
options.logFile = forever.logFilePath(options.uid + '.log');
}
//

@@ -396,3 +411,3 @@ // Create the monitor, log events, and start.

//
//
// This log file is forever's log file - the user's outFile and errFile

@@ -402,3 +417,3 @@ // options are not taken into account here. This will be an aggregate of all

// applicable.
//
//
outFD = fs.openSync(options.logFile, 'a');

@@ -419,2 +434,3 @@ errFD = fs.openSync(options.logFile, 'a');

monitor.unref();
return monitor;
};

@@ -453,3 +469,3 @@

});
worker.start(function (err) {

@@ -515,5 +531,5 @@ return err ? next(err) : next(null, worker);

//
// ### function tail (target, length, callback)
// ### function tail (target, length, callback)
// #### @target {string} Target script to list logs for
// #### @length {number} **Optional** Length of the logs to tail.
// #### @options {length|stream} **Optional** Length of the logs to tail, boolean stream
// #### @callback {function} Continuation to respond to when complete.

@@ -524,26 +540,64 @@ // Responds with the latest `length` logs for the specified `target` process

//
forever.tail = function (target, length, callback) {
if (!callback && typeof length === 'function') {
callback = length;
length = 0;
forever.tail = function (target, options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options.length = 0;
options.stream = false;
}
length = length || forever.config.get('loglength');
if (!length) {
return callback(new Error('Cannot tail logs without a specified length'));
}
function tailProcess(proc, next) {
exec('tail -n ' + [length, proc.logFile].join(' '), function (err, stdout) {
if (err) {
return next(err);
}
proc.logs = stdout.split('\n');
proc.logs.pop();
return err ? next(err) : next(null, proc);
length = options.length || forever.config.get('loglength');
stream = options.stream || forever.config.get('logstream');
var that = this,
blanks = function (e, i, a) { return e !== '' },
title = function (e, i, a) { return e.match(/^==>/) },
args = ['-n', length],
logs;
if (stream) args.unshift('-f');
function tailProcess(procs, next) {
var map = {},
count = 0;
procs.forEach(function (proc) {
args.push(proc.logFile);
map[proc.logFile] = { pid: proc.pid, file: proc.file };
count++;
});
tail = spawn('tail', args, {
stdio: [null, 'pipe', 'pipe'],
});
tail.stdio[1].setEncoding('utf8');
tail.stdio[2].setEncoding('utf8');
tail.stdio[1].on('data', function (data) {
chunk = data.split('\n\n');
chunk.forEach(function (logs) {
var logs = logs.split('\n').filter(blanks),
file = logs.filter(title),
lines,
proc;
file.length
? proc = map[file[0].split(' ')[1]]
: proc = map[procs[0].logFile];
count === 1
? lines = logs
: lines = logs.slice(1);
lines.forEach(function (line) {
callback(null, { file: proc.file, pid: proc.pid, line: line });
});
});
});
tail.stdio[2].on('data', function (err) {
return callback(err);
});
}
getAllProcesses(function (processes) {

@@ -553,11 +607,11 @@ if (!processes) {

}
var procs = forever.findByIndex(target, processes)
|| forever.findByScript(target, processes);
async.mapSeries(procs, tailProcess, function (err, procs) {
return err
? callback(err)
: callback(null, procs);
});
if (!procs) {
return callback(new Error('No logs available for process: ' + target));
}
tailProcess(procs, callback);
});

@@ -573,3 +627,6 @@ };

forever.findByIndex = function (index, processes) {
var proc = processes && processes[parseInt(index, 10)];
var indexAsNum = parseInt(index, 10);
if (indexAsNum == index) {
var proc = processes && processes[indexAsNum];
}
return proc ? [proc] : null;

@@ -621,3 +678,3 @@ };

}
var index = 0,

@@ -627,3 +684,3 @@ columns = forever.config.get('columns'),

formatted;
function mapColumns(prefix, mapFn) {

@@ -671,3 +728,3 @@ return [prefix].concat(columns.map(mapFn));

}
function unlinkProcess(proc, done) {

@@ -717,3 +774,3 @@ fs.unlink(path.join(pidPath, proc.uid + '.pid'), function () {

}
function checkProcess(proc, next) {

@@ -755,7 +812,7 @@ proc.child = forever.checkProcess(proc.pid);

runningLogs;
running = processes && processes.filter(function (p) {
return p && p.logFile;
});
runningLogs = running && running.map(function (p) {

@@ -778,3 +835,3 @@ return p.logFile.split('/').pop();

forever.logFilePath = function (logFile, uid) {
return logFile && logFile[0] === '/'
return logFile && (logFile[0] === '/' || logFile[1] === ':')
? logFile

@@ -790,3 +847,3 @@ : path.join(forever.config.get('root'), logFile || (uid || 'forever') + '.log');

forever.pidFilePath = function (pidFile) {
return pidFile && pidFile[0] === '/'
return pidFile && (pidFile[0] === '/' || pidFile[1] === ':')
? pidFile

@@ -803,16 +860,16 @@ : path.join(forever.config.get('pidPath'), pidFile);

monitor.on('watch:error', function (info) {
console.error(info.message);
console.error(info.error);
forever.out.error(info.message);
forever.out.error(info.error);
});
monitor.on('watch:restart', function (info) {
console.error('restaring script because ' + info.file + ' changed')
forever.out.error('restarting script because ' + info.file + ' changed')
});
monitor.on('restart', function () {
console.error('Forever restarting script for ' + monitor.times + ' time')
forever.out.error('Forever restarting script for ' + monitor.times + ' time')
});
monitor.on('exit:code', function (code) {
console.error('Forever detected script exited with code: ' + code);
forever.out.error('Forever detected script exited with code: ' + code);
});

@@ -863,2 +920,8 @@ };

},
dir: {
color: 'grey',
get: function (proc) {
return proc.sourceDir.grey;
}
},
uptime: {

@@ -865,0 +928,0 @@ color: 'yellow',

@@ -10,6 +10,7 @@ /*

var fs = require('fs'),
path = require('path'),
util = require('util'),
path = require('path'),
colors = require('colors'),
cliff = require('cliff'),
flatiron = require('flatiron'),
cliff = require('cliff'),
forever = require('../forever');

@@ -49,2 +50,4 @@

' -a, --append Append logs',
' -f, --fifo Stream logs to stdout',
' -n, --number Number of log lines to print',
' --pidFile The pid file',

@@ -54,2 +57,4 @@ ' --sourceDir The source directory for which SCRIPT is relative to',

' --spinSleepTime Time to wait (millis) between launches of a spinning script.',
' --colors --no-colors will disable output coloring',
' --plain alias of --no-colors',
' --plain Disable command line colors',

@@ -61,2 +66,3 @@ ' -d, --debug Forces forever to log debug output',

' --watchDirectory Top-level directory to watch from',
' --watchIgnore To ignore pattern when watch is enabled (multiple option is allowed)',
' -h, --help You\'re staring at it',

@@ -80,13 +86,13 @@ '',

var actions = [
'start',
'stop',
'start',
'stop',
'stopall',
'restart',
'restartall',
'list',
'config',
'set',
'list',
'config',
'set',
'clear',
'logs',
'columns',
'columns',
'cleanlogs'

@@ -100,2 +106,4 @@ ];

'append': {alias: 'a', boolean: true},
'fifo': {alias: 'f', boolean: false},
'number': {alias: 'n'},
'max': {alias: 'm'},

@@ -130,2 +138,3 @@ 'outFile': {alias: 'o'},

if (options.path) forever.config.set('root', options.path);
fullLog = forever.logFilePath(options.logFile, options.uid);

@@ -200,7 +209,25 @@ fullScript = path.join(options.sourceDir, file);

'silent', 'outFile', 'max', 'command', 'path', 'spinSleepTime',
'sourceDir', 'uid', 'watchDirectory'
'sourceDir', 'uid', 'watchDirectory', 'watchIgnore', 'killTree', 'killSignal'
].forEach(function (key) {
options[key] = app.config.get(key);
});
options.watchIgnore = options.watchIgnore || [];
options.watchIgnorePatterns = !Array.isArray(options.watchIgnore)
? options.watchIgnore
: [options.watchIgnore];
if (!options.minUptime) {
forever.log.warn('--minUptime not set. Defaulting to: 1000ms');
options.minUptime = 1000;
}
if (!options.spinSleepTime) {
forever.log.warn([
'--spinSleepTime not set. Your script',
'will exit if it does not stay up for',
'at least ' + options.minUptime + 'ms'
].join(' '));
}
options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/');

@@ -256,2 +283,3 @@ if (options.sourceDir) {

forever.log.error('Forever cannot find process with index: ' + file);
process.exit(1);
});

@@ -280,2 +308,3 @@ });

forever.log.info('No forever processes running');
process.exit(1);
});

@@ -285,4 +314,4 @@ });

//
// ### function stopall ()
// Stops all currently running forever processes.
// ### function restartall ()
// Restarts all currently running forever processes.
//

@@ -302,2 +331,6 @@ app.cmd('restartall', cli.restartAll = function () {

});
runner.on('error', function () {
forever.log.info('No forever processes running');
});
});

@@ -327,2 +360,3 @@

forever.log.error(err.message);
process.exit(1);
});

@@ -407,16 +441,17 @@ });

// #### @target {string} Target script or index to list logs for
// Displays the logs using `tail` for the specified `target`.
// Displays the logs using `tail` for the specified `target`.
//
app.cmd('logs :index', cli.logs = function (index) {
forever.tail(index, function (err, logs) {
var options = {
stream: app.argv.fifo,
length: app.argv.number
};
forever.tail(index, options, function (err, log) {
if (err) {
return forever.log.error(err.message);
}
logs.forEach(function (proc) {
forever.log.info('Showing logs for ' + proc.file.magenta);
proc.logs.forEach(function (line) {
forever.log.data(line);
});
});
forever.log.data(log.file.magenta + ':' + log.pid + ' - ' + log.line);
});

@@ -433,3 +468,3 @@ });

}
var rows = [[' ', 'script', 'logfile']];

@@ -442,3 +477,3 @@ index = 0;

}
forever.log.info('Logs for running Forever processes');

@@ -523,2 +558,13 @@ rows = rows.concat(processes.map(function (proc) {

cli.start = function () {
if (app.argv.v || app.argv.version) {
return console.log('v' + forever.version);
}
//
// Check for --no-colors/--colors and --plain option
//
if ((typeof app.argv.colors !== 'undefined' && !app.argv.colors) || app.argv.plain) {
colors.mode = 'none';
}
if (app.config.get('help')) {

@@ -532,3 +578,3 @@ return util.puts(help.join('\n'));

}
app.start();

@@ -535,0 +581,0 @@ });

@@ -5,3 +5,3 @@ {

"description": "A simple CLI tool for ensuring that a given node script runs continuously (i.e. forever)",
"version": "0.10.0",
"version": "0.10.5",
"author": "Nodejitsu Inc. <info@nodejitsu.com>",

@@ -24,13 +24,14 @@ "maintainers": [

"dependencies": {
"colors": "0.6.0-1",
"cliff": "0.1.8",
"flatiron": "0.2.3",
"forever-monitor": "1.0.1",
"nconf": "0.6.1",
"nssocket": "0.3.8",
"optimist": "0.3.4",
"pkginfo": "0.2.3",
"flatiron": "0.3.5",
"forever-monitor": "1.2.1",
"nconf": "0.6.7",
"nssocket": "0.5.0",
"optimist": "0.4.0",
"pkginfo": "0.3.0",
"timespan": "2.0.1",
"watch": "0.5.1",
"utile": "0.1.2",
"winston": "0.6.2"
"watch": "0.7.0",
"utile": "0.1.7",
"winston": "0.7.0"
},

@@ -41,3 +42,3 @@ "devDependencies": {

"request": "2.x.x",
"vows": "0.6.x"
"vows": "0.7.x"
},

@@ -53,5 +54,5 @@ "bin": {

"engines": {
"node": "0.8.x"
"node": ">= 0.8.x"
}
}

@@ -11,3 +11,3 @@ # forever [![Build Status](https://secure.travis-ci.org/nodejitsu/forever.png)](http://travis-ci.org/nodejitsu/forever)

**Note:** If you are using forever _programatically_ you should install [forever-monitor][0].
**Note:** If you are using forever _programatically_ you should install [forever-monitor][0].

@@ -20,3 +20,3 @@ ``` bash

## Usage
There are two distinct ways to use forever: through the command line interface, or by requiring the forever module in your own code. **Note:** If you are using forever _programatically_ you should install [forever-monitor][0].
There are two distinct ways to use forever: through the command line interface, or by requiring the forever module in your own code. **Note:** If you are using forever _programatically_ you should install [forever-monitor][0].

@@ -28,3 +28,3 @@ ### Using forever from the command line

$ forever --help
usage: forever [options] [action] SCRIPT [script-options]
usage: forever [action] [options] SCRIPT [script-options]

@@ -58,2 +58,4 @@ Monitors the script specified in the current process or as a daemon

-a, --append Append logs
-f, --fifo Stream logs to stdout
-n, --number Number of log lines to print
--pidFile The pid file

@@ -119,5 +121,8 @@ --sourceDir The source directory for which SCRIPT is relative to

### forever.tail (target, [length,] callback)
Responds with the logs from the target script(s) from `tail`. If `length` is provided it is used as the `-n` parameter to `tail`.
### forever.tail (target, options, callback)
Responds with the logs from the target script(s) from `tail`. There are two important options:
* `length` (numeric): is is used as the `-n` parameter to `tail`.
* `stream` (boolean): is is used as the `-f` parameter to `tail`.
### forever.cleanUp ()

@@ -137,6 +142,6 @@ Cleans up any extraneous forever *.pid files that are on the target system. This method returns an EventEmitter that raises the 'cleanUp' event when complete.

#### Author: [Charlie Robbins](http://github.com/indexzero)
#### Contributors: [Fedor Indutny](http://github.com/indutny), [James Halliday](http://substack.net/), [Charlie McConnell](http://github.com/avianflu), [Maciej Malecki](http://github.com/mmalecki)
#### Contributors: [Fedor Indutny](http://github.com/indutny), [James Halliday](http://substack.net/), [Charlie McConnell](http://github.com/avianflu), [Maciej Malecki](http://github.com/mmalecki), [John Lancaster](http://jlank.com)
[0]: http://github.com/nodejitsu/forever-monitor
[1]: http://github.com/nodejitsu/forever-monitor/tree/master/examples
[2]: https://github.com/nodejitsu/forever/blob/master/lib/forever/cli.js
[2]: https://github.com/nodejitsu/forever/blob/master/lib/forever/cli.js

@@ -20,6 +20,6 @@ /*

var that = this;
that.child = spawn('node', [path.join(__dirname, '..', 'fixtures', 'start-daemon.js')]);
setTimeout(function () {
forever.tail(0, that.callback);
forever.tail(0, { length: 1 }, that.callback);
}, 2000);

@@ -29,13 +29,6 @@ },

assert.isNull(err);
assert.isArray(procs);
procs.forEach(function (proc) {
assert.isArray(proc.logs);
assert.isTrue(!!proc.logs.length);
assert.isTrue(proc.logs.length > 10);
// Temporary hack, remove after warnings are gone.
proc.logs = proc.logs.slice(1);
proc.logs.forEach(function (line) {
assert.match(line, /^Logging at/);
});
});
assert.equal(typeof procs, 'object');
assert.ok(procs.file);
assert.ok(procs.pid);
assert.ok(procs.line);
}

@@ -42,0 +35,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc