Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --skipIgnoreFile argument #1025

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"prototypejs": false,
"mootools": false,
"dojo": false,
"esversion": 5,

"devel": true,

Expand Down Expand Up @@ -50,4 +51,4 @@
"trailing": true,
"white": false,
"indent": 2
}
}
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
sudo: false
language: node_js
node_js:
- 4.6
- 6.9
- 4
- 6
- 8
- 10
- 11
branches:
only:
- master
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ In addition to passing forever the path to a script (along with accompanying opt
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/home/myuser/app"
"sourceDir": "/home/myuser/app",
"logFile": "/home/myuser/logs/forever.log",
"outFile": "/home/myuser/logs/out.log",
"errFile": "/home/myuser/logs/error.log"
}
```

Expand Down
42 changes: 21 additions & 21 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ var fs = require('fs'),
cliff = require('cliff'),
nconf = require('nconf'),
nssocket = require('nssocket'),
timespan = require('timespan'),
utile = require('utile'),
winston = require('winston'),
mkdirp = utile.mkdirp,
async = utile.async;
mkdirp = require('mkdirp'),
async = require('async'),
configUtils = require('./util/config-utils');

var forever = exports;

Expand Down Expand Up @@ -50,7 +50,7 @@ forever.initialized = false;
forever.kill = require('forever-monitor').kill;
forever.checkProcess = require('forever-monitor').checkProcess;
forever.root = process.env.FOREVER_ROOT || path.join(process.env.HOME || process.env.USERPROFILE || '/root', '.forever');
forever.config = new nconf.File({ file: path.join(forever.root, 'config.json') });
forever.config = configUtils.initConfigFile(forever.root);
forever.Forever = forever.Monitor = require('forever-monitor').Monitor;
forever.Worker = require('./forever/worker').Worker;
forever.cli = require('./forever/cli');
Expand Down Expand Up @@ -335,22 +335,9 @@ forever.load = function (options) {
forever._debug();
}

//
// Syncronously create the `root` directory
// and the `pid` directory for forever. Although there is
// an additional overhead here of the sync action. It simplifies
// the setup of forever dramatically.
//
function tryCreate(dir) {
try {
fs.mkdirSync(dir, '0755');
}
catch (ex) { }
}

tryCreate(forever.config.get('root'));
tryCreate(forever.config.get('pidPath'));
tryCreate(forever.config.get('sockPath'));
configUtils.tryCreateDir(forever.config.get('root'));
configUtils.tryCreateDir(forever.config.get('pidPath'));
configUtils.tryCreateDir(forever.config.get('sockPath'));

//
// Attempt to save the new `config.json` for forever
Expand Down Expand Up @@ -1037,7 +1024,20 @@ forever.columns = {
uptime: {
color: 'yellow',
get: function (proc) {
return proc.running ? timespan.fromDates(new Date(proc.ctime), new Date()).toString().yellow : "STOPPED".red;
if (!proc.running) {
return "STOPPED".red;
}

var delta = (new Date().getTime() - proc.ctime) / 1000;
var days = Math.floor(delta / 86400);
delta -= days * 86400;
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;
var seconds = delta % 60;

return (days+':'+hours+':'+minutes+':'+seconds).yellow;
}
}
};
38 changes: 20 additions & 18 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var help = [
' --spinSleepTime Time to wait (millis) between launches of a spinning script.',
' --colors --no-colors will disable output coloring',
' --plain alias of --no-colors',
' --skipIgnoreFile Don\'t attempt to read .foreverignore file',
' -d, --debug Forces forever to log debug output',
' -v, --verbose Turns on the verbose messages from Forever',
' -s, --silent Run the child script silencing stdout and stderr',
Expand Down Expand Up @@ -107,23 +108,24 @@ var actions = [
];

var argvOptions = cli.argvOptions = {
'command': {alias: 'c'},
'errFile': {alias: 'e'},
'logFile': {alias: 'l'},
'killTree': {alias: 't', boolean: true},
'append': {alias: 'a', boolean: true},
'fifo': {alias: 'f', boolean: true},
'number': {alias: 'n'},
'max': {alias: 'm'},
'outFile': {alias: 'o'},
'path': {alias: 'p'},
'help': {alias: 'h'},
'silent': {alias: 's', boolean: true},
'verbose': {alias: 'v', boolean: true},
'watch': {alias: 'w', boolean: true},
'debug': {alias: 'd', boolean: true},
'plain': {boolean: true},
'uid': {alias: 'u'}
'command': {alias: 'c'},
'errFile': {alias: 'e'},
'logFile': {alias: 'l'},
'killTree': {alias: 't', boolean: true},
'append': {alias: 'a', boolean: true},
'fifo': {alias: 'f', boolean: true},
'number': {alias: 'n'},
'max': {alias: 'm'},
'outFile': {alias: 'o'},
'path': {alias: 'p'},
'help': {alias: 'h'},
'silent': {alias: 's', boolean: true},
'skipIgnoreFile': {boolean: false},
'verbose': {alias: 'v', boolean: true},
'watch': {alias: 'w', boolean: true},
'debug': {alias: 'd', boolean: true},
'plain': {boolean: true},
'uid': {alias: 'u'}
};

app.use(flatiron.plugins.cli, {
Expand Down Expand Up @@ -206,7 +208,7 @@ var getOptions = cli.getOptions = function (file) {
absFile = isAbsolute(file) ? file : path.resolve(process.cwd(), file),
configKeys = [
'pidFile', 'logFile', 'errFile', 'watch', 'minUptime', 'append',
'silent', 'outFile', 'max', 'command', 'path', 'spinSleepTime',
'silent', 'skipIgnoreFile', 'outFile', 'max', 'command', 'path', 'spinSleepTime',
'sourceDir', 'workingDir', 'uid', 'watchDirectory', 'watchIgnore',
'killTree', 'killSignal', 'id'
],
Expand Down
2 changes: 1 addition & 1 deletion lib/forever/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Worker.prototype.start = function (callback) {
// as a mapping to the `\\.pipe\\*` "files" that can't
// be enumerated because ... Windows.
//
fs.unlink(self._sockFile);
fs.unlinkSync(self._sockFile);
}

self.monitor.stop();
Expand Down
29 changes: 29 additions & 0 deletions lib/util/config-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var path = require('path');
var fs = require('fs');
var nconf = require('nconf');

function initConfigFile(foreverRoot) {
return new nconf.File({file: path.join(foreverRoot, 'config.json')});
}

//
// Synchronously create the `root` directory
// and the `pid` directory for forever. Although there is
// an additional overhead here of the sync action. It simplifies
// the setup of forever dramatically.
//
function tryCreateDir(dir) {
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, '0755');
}
}
catch (error) {
throw new Error('Failed to create directory '+dir+":" +error.message);
}
}

module.exports = {
initConfigFile: initConfigFile,
tryCreateDir: tryCreateDir
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,29 @@
"tools"
],
"dependencies": {
"async": "~0.2.9",
"cliff": "~0.1.9",
"clone": "^1.0.2",
"colors": "~0.6.2",
"flatiron": "~0.4.2",
"forever-monitor": "~1.7.0",
"nconf": "~0.6.9",
"mkdirp": "0.x.x",
"nssocket": "~0.5.1",
"object-assign": "^3.0.0",
"optimist": "~0.6.0",
"path-is-absolute": "~1.0.0",
"prettyjson": "^1.1.2",
"shush": "^1.0.0",
"timespan": "~2.3.0",
"utile": "~0.2.1",
"utile": "~0.3.0",
"winston": "~0.8.1"
},
"devDependencies": {
"broadway": "~0.3.6",
"chai": "^4.2.0",
"eventemitter2": "0.4.x",
"mocha": "^3.5.3",
"moment": "^2.23.0",
"request": "2.x.x",
"vows": "0.7.x"
},
Expand Down
2 changes: 1 addition & 1 deletion test/core/start-stop-json-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var assert = require('assert'),
path = require('path'),
fs = require('fs'),
vows = require('vows'),
async = require('utile').async,
async = require('async'),
request = require('request'),
forever = require('../../lib/forever'),
runCmd = require('../helpers').runCmd;
Expand Down
28 changes: 28 additions & 0 deletions test/core/uptime-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var assert = require('assert'),
vows = require('vows'),
moment = require('moment'),
forever = require('../../lib/forever');

vows.describe('forever/core/uptime').addBatch({
"When using forever" : {
"calculates uptime" : {
"for not running process correctly": function (err, procs) {
assert.equal(forever.columns.uptime.get({}), 'STOPPED'.red);
},
"for running process correctly": function (err, procs) {
var launchTime = moment.utc()
.subtract(4000, 'days')
.subtract(6, 'hours')
.subtract(8, 'minutes')
.subtract(25, 'seconds');

var timeWithoutMsecs = forever.columns.uptime.get({
running: true,
ctime: launchTime.toDate().getTime()
}).strip.split('.')[0];

assert.equal(timeWithoutMsecs, '4000:6:8:25');
}
}
}
}).export(module);
30 changes: 30 additions & 0 deletions test/util/config-utils-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var fs = require('fs');
var configUtils = require('../../lib/util/config-utils');
var expect = require('chai').expect;

describe('config-utils', () => {
describe('tryCreateDir', () => {
it('happy path', () => {
expect(() => {
configUtils.tryCreateDir('happypath');
}).to.not.throw();

expect(fs.existsSync('happypath')).to.equal(true);
fs.rmdirSync('happypath');
});

it('throws an error on invalid directory', () => {
expect(() => {
configUtils.tryCreateDir('');
}).to.throw(/Failed to create directory :ENOENT: no such file or directory, mkdir/);
});

it('does not fail when creating directory that already exists', () => {
expect(() => {
configUtils.tryCreateDir('dummy');
configUtils.tryCreateDir('dummy');
}).to.not.throw();
fs.rmdirSync('dummy');
});
});
});