Skip to content

Commit

Permalink
Merge pull request #741 from foreverjs/config-file-args
Browse files Browse the repository at this point in the history
Allow "args" to be set in config files.
  • Loading branch information
indexzero committed Jul 31, 2015
2 parents dffa303 + 602ff87 commit 2f0552a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 53 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,23 @@ JSON configuration files can also be used to define the startup options for *mul

```
[
{
// App1
"uid": "app1",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/home/myuser/app1"
},
{
// App2
"uid": "app2",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/home/myuser/app2"
}
{
// App1
"uid": "app1",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/home/myuser/app1"
},
{
// App2
"uid": "app2",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/home/myuser/app2",
"args": ["--port", "8081"]
}
]
```

Expand Down
6 changes: 5 additions & 1 deletion lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ var getOptions = cli.getOptions = function (file) {
'sourceDir', 'workingDir', 'uid', 'watchDirectory', 'watchIgnore',
'killTree', 'killSignal', 'id'
],
specialKeys = ['script', 'args'],
configs;

//
Expand All @@ -221,7 +222,10 @@ var getOptions = cli.getOptions = function (file) {
configs = configs.map(function (conf) {
var mut = Object.keys(conf)
.reduce(function (acc, key) {
if (~configKeys.indexOf(key) || key === 'script') { acc[key] = conf[key]; }
if (~configKeys.indexOf(key) || ~specialKeys.indexOf(key)) {
acc[key] = conf[key];
}

return acc;
}, {});

Expand Down
18 changes: 18 additions & 0 deletions test/core/start-stop-json-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var assert = require('assert'),
path = require('path'),
fs = require('fs'),
vows = require('vows'),
async = require('utile').async,
request = require('request'),
forever = require('../../lib/forever'),
runCmd = require('../helpers').runCmd;

Expand All @@ -31,6 +33,22 @@ vows.describe('forever/core/start-stop-json-array').addBatch({
}
}
}
}).addBatch({
"When the script is running": {
"request to both ports": {
topic: function () {
async.parallel({
one: async.apply(request, { uri: 'http://localhost:8080', json: true }),
two: async.apply(request, { uri: 'http://localhost:8081', json: true })
}, this.callback);
},
"should respond correctly": function (err, results) {
assert.isNull(err);
assert.isTrue(!results.one[1].p);
assert.equal(results.two[1].p, 8081);
}
}
}
}).addBatch({
"When the script is running" : {
"try to stopall" : {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ var util = require('util'),
http = require('http'),
argv = require('optimist').argv;

var port = argv.p || argv.port || 80;
var port = argv.p || argv.port || 8080;

http.createServer(function (req, res) {
console.log(req.method + ' request: ' + req.url);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello, i know nodejitsu.');
res.write(JSON.stringify(argv));
res.end();
}).listen(port);

Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/server.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"uid": "server",
"append": true,
"script": "server.js",
"sourceDir": "./test/fixtures"
"uid": "server",
"append": true,
"script": "server.js",
"sourceDir": "./test/fixtures"
}
16 changes: 0 additions & 16 deletions test/fixtures/server2.js

This file was deleted.

25 changes: 13 additions & 12 deletions test/fixtures/servers.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[
{
"uid": "server1",
"append": true,
"script": "server.js",
"sourceDir": "./test/fixtures"
},
{
"uid": "server2",
"append": true,
"script": "server2.js",
"sourceDir": "./test/fixtures"
}
{
"uid": "server1",
"append": true,
"script": "server.js",
"sourceDir": "./test/fixtures"
},
{
"uid": "server2",
"append": true,
"script": "server.js",
"sourceDir": "./test/fixtures",
"args": ["-p", 8081]
}
]
4 changes: 2 additions & 2 deletions test/worker/multiple-workers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ var children = [],
function assertRunning(port, i) {
return {
topic: function () {
request('http://127.0.0.1:' + port, this.callback);
request({ uri: 'http://127.0.0.1:' + port, json: true }, this.callback);
},
"should respond with `i know nodejitsu`": function (err, res, body) {
assert.isNull(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'hello, i know nodejitsu.');
assert.equal(body.port, port);
},
"stop the child process": function () {
children[i].stop();
Expand Down

0 comments on commit 2f0552a

Please sign in to comment.