Skip to content

Force complete restart of app (reload config/initializers/*) when .env changes, with foreman? #378

@sbull

Description

@sbull

Similar to the issue described here, I've got some setup in my config/initializers that depend on environment settings. These are loaded from my .env file via foreman. I start up a rails console with foreman run rails c.

In config/spring.rb, I have:

Spring.watch '.env'

Watching spring's log, I can see that any time I change .env, the app re-forks:
[application:development] running -> watcher_stale
[application:development] watcher_stale -> exiting
[application_manager:development] child 22272 shutdown
[application:development] preloading app

At this point, when I run foreman run rails c again, I can access the changes in ENV[...]. However, the config/initializers files are not re-run with the ENV updates, so the old app settings persist.

Is there perhaps a way to force spring to shut down when certain files are changed? Since spring gets started automatically for me, I'm guessing the easiest way to get my changed settings into spring via foreman is with a complete kill and restart of spring.

Perhaps something like Spring.watch('.env', action: :shutdown)?

I'm on Rails 4.2.0, Spring 1.2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions