diff --git a/lib/forever.js b/lib/forever.js index b451e59f..7298b63e 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -157,9 +157,9 @@ function getAllPids(processes) { // // ### function stopOrRestart (action, event, format, target) // #### @action {string} Action that is to be sent to target(s). -// #### @event {string} Event that will be emitted on success. +// #### @event {string} Event that will be emitted on success. // #### @format {boolean} Indicated if we should CLI format the returned output. -// #### @target {string} Index or script name to stop. Optional. +// #### @target {string} Index or script name to stop. Optional. // #### If not provided -> action will be sent to all targets. // Returns emitter that you can use to handle events on failure or success (i.e 'error' or ) // @@ -225,9 +225,9 @@ function stopOrRestart(action, event, format, target) { // // ### function stopByPid(event, format, pid) -// #### @event {string} Event that will be emitted on success. +// #### @event {string} Event that will be emitted on success. // #### @format {boolean} Indicated if we should CLI format the returned output. -// #### @pid {string} Pid of the process to stop. Optional. +// #### @pid {string} Pid of the process to stop. Optional. // Returns emitter that you can use to handle events on failure or success (i.e 'error' or ) // function stopByPid(event, format, pid) { @@ -473,7 +473,7 @@ forever.startDaemon = function (script, options) { options.logFile = forever.logFilePath(options.logFile || forever.config.get('logFile') || options.uid + '.log'); options.pidFile = forever.pidFilePath(options.pidFile || forever.config.get('pidFile') || options.uid + '.pid'); - var monitor, outFD, errFD, workerPath; + var monitor, outFD, errFD, monitorPath; // // This log file is forever's log file - the user's outFile and errFile @@ -576,7 +576,7 @@ forever.restart = function (target, format) { // ### function stopbypid (target, format) // #### @pid {string} Pid of process to stop. // #### @format {boolean} Indicated if we should CLI format the returned output. -// Stops the process with specified pid +// Stops the process with specified pid // forever.stopbypid = function (pid, format) { // stopByPid only capable of stopping, but can't restart @@ -629,20 +629,20 @@ forever.tail = function (target, options, callback) { options.stream = false; } - 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], + var that = this, + length = options.length || forever.config.get('loglength'), + stream = options.stream || forever.config.get('logstream'), + blanks = function (e, i, a) { return e !== ''; }, + title = function (e, i, a) { return e.match(/^==>/); }, + args = ['-n', length], logs; - if (stream) args.unshift('-f'); + if (stream) { args.unshift('-f'); } function tailProcess(procs, next) { - var map = {}, - count = 0; + var count = 0, + map = {}, + tail; procs.forEach(function (proc) { args.push(proc.logFile); @@ -658,20 +658,20 @@ forever.tail = function (target, options, callback) { tail.stdio[2].setEncoding('utf8'); tail.stdio[1].on('data', function (data) { - chunk = data.split('\n\n'); + var 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]; + proc = file.length + ? map[file[0].split(' ')[1]] + : map[procs[0].logFile]; - count === 1 - ? lines = logs - : lines = logs.slice(1); + lines = count !== 1 + ? logs.slice(1) + : logs; lines.forEach(function (line) { callback(null, { file: proc.file, pid: proc.pid, line: line }); @@ -710,14 +710,13 @@ forever.tail = function (target, options, callback) { // Finds the process with the specified index. // forever.findById = function (id, processes) { - if (!processes) return null; + if (!processes) { return null; } var procs = processes.filter(function (p) { return p.id == id; }); - if (procs.length === 0) procs = null; - + if (procs.length === 0) { procs = null; } return procs; }; @@ -728,9 +727,11 @@ forever.findById = function (id, processes) { // Finds the process with the specified index. // forever.findByIndex = function (index, processes) { - var indexAsNum = parseInt(index, 10); + var indexAsNum = parseInt(index, 10), + proc; + if (indexAsNum == index) { - var proc = processes && processes[indexAsNum]; + proc = processes && processes[indexAsNum]; } return proc ? [proc] : null; }; @@ -742,16 +743,18 @@ forever.findByIndex = function (index, processes) { // Finds the process with the specified script name. // forever.findByScript = function (script, processes) { - if (!processes) return null; + if (!processes) { return null; } // make script absolute. - script.indexOf('/') != 0 && (script = path.resolve(process.cwd(), script)); + if (script.indexOf('/') != 0) { + script = path.resolve(process.cwd(), script); + } + var procs = processes.filter(function (p) { return p.file === script || path.join(p.spawnWith.cwd, p.file) === script; }); - if (procs.length === 0) procs = null; - + if (procs.length === 0) { procs = null; } return procs; }; diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 79dd9b3c..37472dc5 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -237,12 +237,12 @@ var getOptions = cli.getOptions = function (file) { ].join(' ')); } - options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/'); + options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/'); options.workingDir = options.workingDir || options.sourceDir; - options.spawnWith = {cwd: options.workingDir}; + options.spawnWith = { cwd: options.workingDir }; return options; -} +}; // // ### function cleanLogs @@ -540,7 +540,7 @@ app.cmd(/columns set (.*)/, cli.setColumns = function (columns) { }); app.cmd('columns reset', cli.resetColumns = function () { - columns = 'uid command script forever pid logfile uptime' + var columns = 'uid command script forever pid logfile uptime'; forever.log.info('Setting columns: ' + columns.magenta); diff --git a/lib/forever/worker.js b/lib/forever/worker.js index ec08bd7d..951a1dc5 100644 --- a/lib/forever/worker.js +++ b/lib/forever/worker.js @@ -7,7 +7,7 @@ var events = require('events'), var Worker = exports.Worker = function (options) { events.EventEmitter.call(this); - options || (options = {}); + options = options || {}; this.monitor = options.monitor; this.sockPath = options.sockPath || forever.config.get('sockPath'); @@ -38,7 +38,7 @@ Worker.prototype.start = function (callback) { function workerProtocol(socket) { socket.on('error', function() { socket.destroy(); - }) + }); socket.data(['ping'], function () { socket.send(['pong']); @@ -68,7 +68,9 @@ Worker.prototype.start = function (callback) { socket.data(['stop'], function () { self.monitor.once('stop', function () { socket.send(['stop', 'ok']); - self.exitOnStop && process.exit(); + if (self.exitOnStop) { + process.exit(); + } }); if (process.platform === 'win32') { @@ -100,15 +102,18 @@ Worker.prototype.start = function (callback) { // `listening` listener doesn't take error as the first parameter // self.emit('start'); - callback && callback(null, self._sockFile); + if (callback) { + callback(null, self._sockFile); + } }); self._socket.on('error', function (err) { if (err.code === 'EADDRINUSE') { return findAndStart(); } - - callback && callback(err); + else if (callback) { + callback(err); + } }); // diff --git a/test/core/daemonic-inheritance-test.js b/test/core/daemonic-inheritance-test.js index 390fae28..80641a6a 100644 --- a/test/core/daemonic-inheritance-test.js +++ b/test/core/daemonic-inheritance-test.js @@ -23,15 +23,16 @@ vows.describe('forever/core/startDaemon').addBatch({ "When using forever" : { "the startDaemon() method with customized configuration" : { topic: function () { - !fs.existsSync(myRoot) && fs.mkdirSync(myRoot); + if (!fs.existsSync(myRoot)) { + fs.mkdirSync(myRoot); + } forever.load({root:myRoot}); forever.startDaemon(path.join(__dirname, '..', 'fixtures', 'log-on-interval.js')); setTimeout(function (that) { forever.list(false, that.callback); - }, 2000, this) - //forever.tail(0, { length: 1 }, that.callback); + }, 2000, this); }, "should respond with 1 process": function (err, procs) { assert.isNull(err); diff --git a/test/core/start-stop-relative-test.js b/test/core/start-stop-relative-test.js index a313a833..56190f44 100644 --- a/test/core/start-stop-relative-test.js +++ b/test/core/start-stop-relative-test.js @@ -31,7 +31,7 @@ vows.describe('forever/core/start-stop-peaceful').addBatch({ ]); setTimeout(function (that) { forever.list(false, that.callback); - }, 2000, this) + }, 2000, this); }, "the startup should works fine": function (err, procs) { assert.isNull(err); @@ -49,7 +49,7 @@ vows.describe('forever/core/start-stop-peaceful').addBatch({ ]); setTimeout(function (that) { forever.list(false, that.callback); - }, 2000, this) + }, 2000, this); }, "the shut down should works fine": function (err, procs) { assert.isNull(err); diff --git a/test/helpers/macros.js b/test/helpers/macros.js index dcdde10f..30763fad 100644 --- a/test/helpers/macros.js +++ b/test/helpers/macros.js @@ -27,7 +27,7 @@ macros.assertTimes = function (script, times, options) { "should emit 'exit' when completed": function (err, child) { assert.equal(child.times, times); } - } + }; }; macros.spawn = function (args, options) { @@ -61,7 +61,7 @@ macros.spawn = function (args, options) { macros.list = function (options) { options.topic = function () { - forever.list(false, this.callback) + forever.list(false, this.callback); }; return options; }; diff --git a/test/helpers/mocks/monitor.js b/test/helpers/mocks/monitor.js index 411780d6..4dbea4cd 100644 --- a/test/helpers/mocks/monitor.js +++ b/test/helpers/mocks/monitor.js @@ -14,7 +14,7 @@ MonitorMock.prototype.__defineGetter__('data', function () { return { uid: '_uid', command: 'node' - } + }; }); MonitorMock.prototype.kill = MonitorMock.prototype.stop = function (forceStop) { diff --git a/test/worker/multiple-workers-test.js b/test/worker/multiple-workers-test.js index 2f5cdc9e..de995bba 100644 --- a/test/worker/multiple-workers-test.js +++ b/test/worker/multiple-workers-test.js @@ -32,7 +32,7 @@ function assertRunning(port, i) { "stop the child process": function () { children[i].stop(); } - } + }; } vows.describe('forever/workers/multiple').addBatch({