Skip to content

Conversation

@tkambler
Copy link
Contributor

This PR adds support for JSON configuration files. Consider the following example:

.
├── forever
│   └── development.json
└── index.js

// forever/development.json
{
    "uid": "app",
    "append": true,
    "watch": true,
    "script": "index.js",
    "sourceDir": "/Users/tim/Desktop/app"
}

This PR allows this application to be started with:

$ forever start ./forever/development.json

It also supports the use of absolute paths:

$ forever start /home/myuser/app/forever/development.json

While creating this PR and digging through the source code, it occurred to me that I'm a little unclear as to the intended use case for forever, given its current state. Forever seems to want to load global configuration values from ~/.forever/config.json; however, wouldn't this prevent forever from being used with multiple apps at the same time? What if I have five separate processes that I want to monitor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to add lodash as a dependency for a single function. Lets use this instead: https://github.com/sindresorhus/object-assign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually using _.pick() as well, but I'll see what I can do.

@indexzero
Copy link
Member

Good start @tkambler. Made some comments. Could you also add test coverage for this? We need it.

@tkambler
Copy link
Contributor Author

👍 expect some updates tomorrow.

@tkambler
Copy link
Contributor Author

@indexzero Updates in place.

@indexzero
Copy link
Member

Moving in the right direction! Any idea why the tests are failing? I believe master is passing...

@tkambler
Copy link
Contributor Author

Was going to ask you the same thing. Everything passes locally...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am being super picky here but just because we got rid of lodash doesn't mean we have to throw functional programming out the window 😄

jsonConfig = Object.keys(jsonConfig)
  .reduce(function (acc, k) {
    if (!~configKeys.indexOf(k) && k !== 'script') { acc[k] = jsonConfig[k]; }
    return acc;
  }, {});

@indexzero
Copy link
Member

Passes locally for me as well. Very strange indeed. I wonder what Travis is doing special. I'll see if I can investigate, but if not lets get this merged anyway. The tests are in a bit of a sordid place anyway.

@tkambler
Copy link
Contributor Author

👍

@indexzero
Copy link
Member

@tkambler after rereading #260, #591, and #600 a consistent theme was being able to start multiple processes from a single file. Based on your PR it seems if the JSON file was an Array this would work just fine:

// my-app/development.json
[{
  "uid": "app",
  "append": true,
  "watch": true,
  "script": "index.js",
  "sourceDir": "/Users/tim/Desktop/app"
}, {
  "uid": "other-service",
  "append": true,
  "watch": true,
  "script": "other-service.js",
  "sourceDir": "/Users/tim/Desktop/app"
}]

Thoughts?

@tkambler
Copy link
Contributor Author

Absolutely. As a matter of fact, I had intended to submit a separate PR for precisely that once this got merged, but if you'd like me to go ahead and add support for that now, it would obviously be trivial at this point.

@indexzero
Copy link
Member

No, I'll leave it up to you after this merges 👍 💪 💯

indexzero added a commit that referenced this pull request Jul 22, 2015
Adds support for JSON configuration values
@indexzero indexzero merged commit e05db8d into foreversd:master Jul 22, 2015
@alexblack
Copy link

Is there a way to pass command line parameters via the config.json? eg

[{
  "uid": "index-3000",
  "append": true,
  "watch": true,
  "script": "index.js",
  "args": ["3000"],
  "sourceDir": "/Users/tim/Desktop/app"
}, {
  "uid": "index-3001",
  "append": true,
  "watch": true,
  "script": "index.js",
  "args": ["3001"],
  "sourceDir": "/Users/tim/Desktop/app"
}]

@indexzero
Copy link
Member

It is now: #741

@indexzero
Copy link
Member

This fix went out in 0.15.1. Good find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants