Rails - Nginx needs to be restarted after deploying with Capistrano? Rails - Nginx needs to be restarted after deploying with Capistrano? nginx nginx

Rails - Nginx needs to be restarted after deploying with Capistrano?


You shouldn't have to restart or reload nginx. Just touching tmp/restart.txt should be enough to tell passenger to reload the app.

If you're using a recent version of capistrano, you can even drop entire 'namespace :deploy' part. Capistrano already touches tmp/restart.txt after a successful deploy.


I realized that the deployment setup matcheshttp://coding.smashingmagazine.com/2011/06/28/setup-a-ubuntu-vps-for-hosting-ruby-on-rails-applications-2/

When I followed this tutorial(about a year ago), I installed slightly newer versions of nginx and passenger. From what I remember, I think these newer versions prompted me to use nginx as a service when I ran any type of init.d command. (Ubuntu 10.04)

Anyways I would switch out the code

run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

to

run "#{sudo} service nginx #{command}"

And see if that works.


Maybe the problem is in how exactly you started Passenger. Capistrano points the symlink 'current' to the latest release. The task

run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

is using that 'current' to place the restart.txt. But according to http://code.google.com/p/phusion-passenger/issues/detail?id=547 , Passenger is "pinned" to the 'current' it was started in, while the task writes 'restart.txt' to the current 'current', so to speak. So Passenger doesn't "see" that it's supposed to restart.

If you cd'ed to the then 'current' and started Passenger from there, it gets pinned to the directory the 'current' symlink points to at that point and doesn't follow the changes of the symlink. So you might need to get rid of the 'cd ... && passenger start...' and provide the path to Passenger directly. I extended the deploy:start and deploy:stop tasks you have in your recipie as well to say

task :start, :roles => :app, :except => { :no_release => true } do  run "passenger start #{current_path} -a 127.0.0.1 -p 3000 -e production -d"endtask :stop, :roles => :app, :except => { :no_release => true } do  run "passenger stop #{current_path} -p 3000"end