-
Notifications
You must be signed in to change notification settings - Fork 82
Setting env-vars (in .rbenv_vars) is not picked up by the app. #159
Comments
Hi @berkes, Thank you for opening the issue. Can you please tell what capistrano plugin do you use for reloading unicorn? Is it https://github.com/capistrano-plugins/capistrano-unicorn-nginx ? |
I've found out that capistrano plugins restart unicorn differently. For example capistrano-unicorn sends desc 'Reload Unicorn'
task :reload, :roles => unicorn_roles, :except => {:no_release => true} do
run <<-END
if #{unicorn_is_running?}; then
echo "Reloading Unicorn...";
#{unicorn_send_signal('HUP')};
else
#{start_unicorn}
fi;
END
end This is how it's implemented in capistrano-unicorn-nginx using init script: restart|reload)
sig USR2 && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;; I've also found some info about signals handling is in the Unicorn's docs. I'll try both approaches later to see if it has any difference related to env vars loading from .rbenv-vars. |
Thanks for looking into this. Unicorn is reloaded with capistrano, using capistrano3-unicorn. The code to reload is:
This, indeed, implies that Unicorn gets a
This does cause some strange behaviour. E.g. connections to databases And it will be running in the same ENV, since it inherits this from the Restarting (not the reload explained above, but a full blown stop-start sequence) will, however, kill off the threads (letting it finish My personal preference would be to:
That way you don't need to re-deploy after a change in chef-repo and [1]
|
Just for information, sending |
hi, I don't know if it can help but I added this line below in my unicorn config so it loads new env var values :
I'm not using chef repo and capistrano-unicorn3 neither. Hope it'll help |
Using unicorn.
Setting or changing a env-var requires a restart of unicorn. A simple reload (which is the default when using the capistrano setup) will not make these vars available in the app.
I think the
chef-repo/vendor/cookbooks/rails/recipes/setup.rb
Line 32 in 587ad7b
notifies :reload, resources(:service => app_name)
to restart the app after changing these.Case at hand:
I spent about 20- minutes debugging before I found that the issue is simple and the app needed a full restart. Mostly because
bundle exec rails c -e production
did have the correct env-variables and secrets loaded. I'd love to spend some time to avoid others such downtime (and myself, in a few months when I've forgotten about this issue).An alternative solution would be to do a full restart instead of a gracefull (zero downtime) reload with capistrano always. But IMHO the better solution is to immediately make the new env-variables available after changing or setting them by rebooting the app on changing the settings.
The text was updated successfully, but these errors were encountered: