RAILS_ROOT and USR2 restarts
normalperson at yhbt.net
Mon Oct 26 12:01:58 EDT 2009
Ian Leitch <port001 at gmail.com> wrote:
> I've just started using Unicorn in production behind Nginx with a
> Rails app, for the most part its been a smooth transition apart from
> this one issue.
> When I do an in place restart (USR2), the restart process works but
> the workers load my old Rails release, not the new one. I'm guessing
> that because the master process is currently in the old release
> directory, when I signal USR2 it's just reloading inside the current
> directory. I'm deploying with Capistrano, so app/current is a symlink
> to a specific release. I've tried changing to the new release
> directory in before_work but that made no difference. Is there a
> callback that fires before the master preloads the app?
Unicorn chdirs to the directory returned by `/bin/sh -c pwd` when it was
originally started. The output of `pwd` *should* be symlink-aware, but
then Solaris /bin/sh is weird. Can you confirm that it's broken?
You can put the following in your config (outside of the hooks):
app_root = "/var/www/apps/systino_production/current"
Dir.chdir(Unicorn::HttpServer::START_CTX[:cwd] = app_root)
I've been pondering adding a "working_directory" directive to
Configurator, too. However the START_CTX hash is considered a stable
interface and I recently documented it in
START_CTX even allows you to switch between different installation paths
for Unicorn and alter command line options that were originally
passed. Lots of rope there :>
 for different Ruby installs/versions,
or even swap in Rainbows! or vice versa
More information about the mongrel-unicorn