Ruby-on-rails – Rails – Nginx needs to be restarted after deploying with Capistrano

capistranonginxpassengerruby-on-railsruby-on-rails-3

I am using Capistrano to deploy my Rails application. whenever I deploy, changes would not be reflected on the browser, and I still need to restart nginx to update the site (running sudo /etc/init.d/nginx restart). I'm not really sure why but isn't it supposed to be updated after restarting application? (using touch /app/tmp/restart.txt)

Here's my deploy.rb

require "rvm/capistrano"
set :rvm_ruby_string, 'ruby-1.9.3-p194@app_name'
set :rvm_type, :user

require "bundler/capistrano"

set :application, "app_name"
set :user, "me"

set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :copy

set :use_sudo, false

set :scm, :git
set :repository,  "~/Sites/#{application}/.git"
set :branch, "master"

role :web, '1.2.3.4'
role :app, '1.2.3.4'
role :db,  '1.2.3.4', :primary => true
role :db,  '1.2.3.4'

namespace :deploy do
 task :start do ; end
 task :stop do ; end
 task :restart, :roles => :app, :except => { :no_release => true } do
   run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
 end
end

Best Answer

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.

Related Topic