Re-source .bashrc when restarting unicorn?

夙愿已清 提交于 2019-11-29 12:45:13

In the end I went away from this approach altogether in favor of loading my app config from an app_config.yml file. Ryan Bates covers this approach in Railscast #226.

The only thing I did differently is that I load a shared app_config.yml for each server I use. Since I'm using capistrano, I just symlink the file on deploy.

For example, on staging2 my shared/configs/app_config.yml looks like this:

staging:
  host: "staging2.example.com"

... whereas on staging3 it looks like this:

staging:
  host: "staging3.example.com"

Now my application.rb has this line instead:

config.action_mailer.default_url_options = { host: APP_CONFIG[:host] }

I removed the actual config/app_config.yml from git so that it's not included on deploy. (I moved it to config/app_config.yml.template.) Then on deploy I use a capistrano task to symlink shared/configs/app_config.yml to config/app_config.yml:

namespace :deploy do
  desc "Symlinks the app_config.yml"
  task :symlink_app_config, :roles => [:web, :app, :db] do
    run "ln -nfs #{deploy_to}/shared/config/app_config.yml #{release_path}/config/app_config.yml"
  end
end

This strategy has these benefits over using ENV vars:

  • Deployed to all nodes via capistrano
  • We can do conditional hosts by simply changing the file on the appropriate server
  • Unicorn will get changes with USR2 since everything's done inside of rails
  • Everything's kept in one place, and the environment isn't affected by some other variables outside of the codebase
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!