Sidekiq 在 Capistrano 启动时启动并神秘消失

Sidekiq launches and mysteriously disappears when started by Capistrano

我正在努力使用自定义 v2 capistrano 任务远程启动 sidekiq:

namespace :sidekiq do
  desc "Start sidekiq"
  task :start do
    run "cd #{current_path} && bundle exec sidekiq --version"
    run "cd #{current_path} && bundle exec sidekiq --environment production --daemon --config config/sidekiq.yml && echo OK"
  end
end

输出:

  * 2018-01-05 11:40:51 executing `sidekiq:start'
  * executing "cd /home/deploy/applications/xxx/current && bundle exec sidekiq --version"
    servers: ["198.58.110.211"]
    [198.58.110.211] executing command
 ** [out :: 198.58.110.211] Sidekiq 5.0.5
 ** [out :: 198.58.110.211]
    command finished in 1424ms
  * executing "cd /home/deploy/applications/xxx/current && bundle exec sidekiq --environment production --daemon --config config/sidekiq.yml && echo OK"
    servers: ["198.58.110.211"]
    [198.58.110.211] executing command
 ** [out :: 198.58.110.211] OK
    command finished in 1128ms

我可以确认我正在获取第一个 运行 cmd 显示的环境(rbenv 和 bundler 正确)。但出乎意料的是,sidekiq 任务开始并分散到遗忘中:1)tmp/pids/sidekiq.pid 被初始化但进程不存在和 2)logs/sidekiq.log 被创建但仅使用 header:

# Logfile created on 2018-01-05 11:34:09 -0300 by logger.rb/56438

通过在末尾添加 && sleep 1 解决问题,如下所述:http://blog.hartshorne.net/2013/03/capistrano-nohup-and-sleep.html.

  desc "Start sidekiq"
  task :start do
    run "cd #{current_path} && bundle exec sidekiq --environment production --daemon --config config/sidekiq.yml && sleep 1"
  end

感谢@user3309314 为我指明了正确的方向。

如果您使用纯 Capistrano 来守护 Sidekiq,任何崩溃都会导致停机。不要这样做。您需要使用一个进程监视器,它会在 Sidekiq 进程死机时重新启动它。使用 systemd,upstart and/or Foreman,如文档中所述。

https://github.com/mperham/sidekiq/wiki/Deployment#running-your-own-process