好的,我不确定确切的原因,但我认为这就是 SideKiq 的启动方式。它得到了它自己的 pid,并且 runit 也分配了一个。无论如何,我已经通过修改内置的 capistrano 配方解决了这个问题。
基本思想是使用 sidekiqctl 发送 :quite 信号,以便工作人员停止接受新工作。然后在 :stop 我们停止 runit 然后发送 sidekiqctl :stop 信号。在启动时,我们使用 runit 再次启动该过程。
Capistrano::Configuration.instance.load do
_cset(:sidekiq_default_hooks) { true }
_cset(:sidekiq_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" }
_cset(:sidekiqctl_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" }
_cset(:sidekiq_timeout) { 10 }
_cset(:sidekiq_role) { :app }
_cset(:sidekiq_pid) { "#{current_path}/tmp/pids/sidekiq.pid" }
_cset(:sidekiq_processes) { 1 }
if fetch(:sidekiq_default_hooks)
before "deploy:update_code", "sidekiq:quiet"
after "deploy:stop", "sidekiq:stop"
after "deploy:start", "sidekiq:start"
before "deploy:restart", "sidekiq:restart"
end
namespace :sidekiq do
def for_each_process(&block)
fetch(:sidekiq_processes).times do |idx|
yield((idx == 0 ? "#{fetch(:sidekiq_pid)}" : "#{fetch(:sidekiq_pid)}-#{idx}"), idx)
end
end
desc "Quiet sidekiq (stop accepting new work)"
task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
for_each_process do |pid_file, idx|
run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} quiet #{pid_file} ; else echo 'Sidekiq is not running'; fi"
end
end
desc "Stop sidekiq"
task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
for_each_process do |pid_file, idx|
sidekiq_dir = idx == 0 ? "/SERVICE_DIR/sidekiq" : "/SERVICE_DIR/sidekiq-#{idx}"
run "sv stop #{sidekiq_dir}"
run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} stop #{pid_file} #{fetch :sidekiq_timeout} ; else echo 'Sidekiq is not running'; fi"
end
end
desc "Start sidekiq"
task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
rails_env = fetch(:rails_env, "production")
for_each_process do |pid_file, idx|
sidekiq_dir = idx == 0 ? "/SERVICE_DIR/sidekiq" : "/SERVICE_DIR/sidekiq-#{idx}"
run "sv start #{sidekiq_dir}"
end
end
desc "Restart sidekiq"
task :restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
stop
start
end
end
end