Search code examples
ruby-on-railscapistrano

Capistrano not restarting nginx


I have setup Capistrano and eveything is working fine except Capistrano is not restarting passenger after deployment. Eveytime after deployment I have to ssh into server and type touch tmp/restart.txt inside current directory. I tried different ways to restart passenger but nothing is working for me.

first attempt:

namespace :deploy do
  task :restart do
    on roles(:app) do
      run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
    end
  end
end

second attempt

namespace :deploy do
  task :restart do
    on roles(:app) do
      within current_path do
         execute :touch, 'tmp/restart.txt'
      end
    end
  end
end

third attempt

namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

I found above code snippets in stackoverflow with similar problem to mine but none of them is restarting the server.

I am using capistrano (3.4.0) with Rails 4 (nginx + passenger)


Solution

  • It could be that your deploy:restart task is not being executed.

    Capistrano 3.1.0 and higher (as explained in the Capistrano's CHANGELOG), does not automatically execute deploy:restart at the end of cap deploy.

    You must therefore explicitly tell Capistrano to do so, by adding this to your deploy.rb:

    after 'deploy:publishing', 'deploy:restart'