From 6b2702d01e39d72d248b9fbf4fd70de8104b6b2a Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 5 Jan 2019 17:21:01 +0100 Subject: [PATCH 1/7] Execute tests in CI on newer Node.js versions (#1013) --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a3419ab..8dae480f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ sudo: false language: node_js node_js: - - 4.6 - - 6.9 + - 4 + - 6 + - 8 + - 10 + - 11 branches: only: - master From caaa60c9b6277ff8ba31aaea7502a1a4eae7aba2 Mon Sep 17 00:00:00 2001 From: Adam Reis Date: Sun, 6 Jan 2019 05:38:13 +1300 Subject: [PATCH 2/7] Add example for referencing -l -o and -e parameters from within a JSON config file (#869) --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fcbee4c..ce865ee7 100644 --- a/README.md +++ b/README.md @@ -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" } ``` From 004ee49c49858e35aea98c85a20c82e61186d903 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 5 Jan 2019 17:40:49 +0100 Subject: [PATCH 3/7] [fix] use fs.unlinkSync (#979) Right now fs.unlink is used without a callback. This would throw from Node.js 10 on. Therefore switch to the sync version. That way errors are also going to be detected. --- lib/forever/worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/forever/worker.js b/lib/forever/worker.js index 4c0228a5..d17b3f65 100644 --- a/lib/forever/worker.js +++ b/lib/forever/worker.js @@ -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(); From a32e24f9b09ede36e6b5b30f1482289ad76f13d1 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Tue, 8 Jan 2019 07:14:49 +0100 Subject: [PATCH 4/7] Remove dependency on timespan (#1014) * Remove dependency on timespan. Add test to ensure that uptime signature didn't change * Remove redundant description --- .jshintrc | 3 ++- lib/forever.js | 16 ++++++++++++++-- package.json | 2 +- test/core/uptime-test.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test/core/uptime-test.js diff --git a/.jshintrc b/.jshintrc index b7e2f6a3..43449b52 100755 --- a/.jshintrc +++ b/.jshintrc @@ -11,6 +11,7 @@ "prototypejs": false, "mootools": false, "dojo": false, + "esversion": 5, "devel": true, @@ -50,4 +51,4 @@ "trailing": true, "white": false, "indent": 2 -} \ No newline at end of file +} diff --git a/lib/forever.js b/lib/forever.js index a44aa03b..26201081 100755 --- a/lib/forever.js +++ b/lib/forever.js @@ -14,7 +14,6 @@ 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, @@ -1037,7 +1036,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; } } }; diff --git a/package.json b/package.json index 1db6c649..a221bf05 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,13 @@ "path-is-absolute": "~1.0.0", "prettyjson": "^1.1.2", "shush": "^1.0.0", - "timespan": "~2.3.0", "utile": "~0.2.1", "winston": "~0.8.1" }, "devDependencies": { "broadway": "~0.3.6", "eventemitter2": "0.4.x", + "moment": "^2.23.0", "request": "2.x.x", "vows": "0.7.x" }, diff --git a/test/core/uptime-test.js b/test/core/uptime-test.js new file mode 100644 index 00000000..25aebb64 --- /dev/null +++ b/test/core/uptime-test.js @@ -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); From fdece5dbd1909c462d6f664fa446c7562cda3e16 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Wed, 27 Feb 2019 00:30:25 +0100 Subject: [PATCH 5/7] Propagate error when failing to create directories on startup (#1017) --- lib/forever.js | 24 ++++++------------------ lib/util/config-utils.js | 29 +++++++++++++++++++++++++++++ package.json | 2 ++ test/util/config-utils-spec.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 lib/util/config-utils.js create mode 100644 test/util/config-utils-spec.js diff --git a/lib/forever.js b/lib/forever.js index 26201081..986afc40 100755 --- a/lib/forever.js +++ b/lib/forever.js @@ -17,7 +17,8 @@ var fs = require('fs'), utile = require('utile'), winston = require('winston'), mkdirp = utile.mkdirp, - async = utile.async; + async = utile.async, + configUtils = require('./util/config-utils'); var forever = exports; @@ -49,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'); @@ -334,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 diff --git a/lib/util/config-utils.js b/lib/util/config-utils.js new file mode 100644 index 00000000..4bc35a43 --- /dev/null +++ b/lib/util/config-utils.js @@ -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 +}; diff --git a/package.json b/package.json index a221bf05..cb7e7568 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ }, "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" diff --git a/test/util/config-utils-spec.js b/test/util/config-utils-spec.js new file mode 100644 index 00000000..3f144e89 --- /dev/null +++ b/test/util/config-utils-spec.js @@ -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'); + }); + }); +}); From f8eb48c3eb5ecbbe5b2323500e3131aeeb863f61 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Tue, 5 Mar 2019 21:06:45 +0100 Subject: [PATCH 6/7] Update utile to get rid of security warning (#1022) * Update utile to get rid of security warning * Don't use external dependencies from utile --- lib/forever.js | 4 ++-- package.json | 4 +++- test/core/start-stop-json-array-test.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/forever.js b/lib/forever.js index 986afc40..9b023c5c 100755 --- a/lib/forever.js +++ b/lib/forever.js @@ -16,8 +16,8 @@ var fs = require('fs'), nssocket = require('nssocket'), 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; diff --git a/package.json b/package.json index cb7e7568..6bee59ae 100644 --- a/package.json +++ b/package.json @@ -19,19 +19,21 @@ "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", - "utile": "~0.2.1", + "utile": "~0.3.0", "winston": "~0.8.1" }, "devDependencies": { diff --git a/test/core/start-stop-json-array-test.js b/test/core/start-stop-json-array-test.js index 6e9184ec..29339d30 100644 --- a/test/core/start-stop-json-array-test.js +++ b/test/core/start-stop-json-array-test.js @@ -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; From 1547a846ef52a7af2099541f5a5867f89448e291 Mon Sep 17 00:00:00 2001 From: ww9 Date: Thu, 14 Mar 2019 16:40:47 -0400 Subject: [PATCH 7/7] Add --skipIgnoreFile argument --- lib/forever/cli.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/forever/cli.js b/lib/forever/cli.js index e6a284aa..06d42239 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -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', @@ -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, { @@ -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' ],