Capistrano 不重启 nginx

Capistrano not restarting nginx

我已经设置了 Capistrano,除了 Capistrano 在部署后没有重新启动 passenger 之外,一切都工作正常。每次部署后,我都必须通过 ssh 进入服务器并在 current directory 中键入 touch tmp/restart.txt。我尝试了不同的方式来重新启动 passenger,但没有任何效果。

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

我在 Whosebug 中发现上面的代码片段与我的问题类似,但其中 none 正在重启服务器。

我正在使用 capistrano (3.4.0)Rails 4 (nginx + passenger)

可能是您的deploy:restart任务没有被执行。

Capistrano 3.1.0 及更高版本(如 Capistrano's CHANGELOG 中所述),不会在 cap deploy 结束时自动执行 deploy:restart

因此,您必须明确告诉 Capistrano 这样做,方法是将其添加到您的 deploy.rb:

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