ruby-on-rails - 将 Sidekiq 升级到 v6 后,它不会在生产环境中自动启动

标签 ruby-on-rails ruby ubuntu capistrano sidekiq

这是 Capistrano 的输出:

02:05 sidekiq:start
      01 sudo service sidekiq start index=1
      01 sidekiq (1) start/running, process 26392
    ✔ 01 deployer@IP 0.721s
      02 sudo service sidekiq start index=2
      02 sidekiq (2) start/running, process 26505
    ✔ 02 deployer@IP 0.728s

登录到服务器和 ps aux | grep sidekiq 后,没有进程在运行。所以我回到我的本地终端选项卡并运行
cap staging sidekiq:start

新的 Sidekiq 进程会在服务器上显示几秒钟:
ps aux | grep sidekiq
deployer   489 52.0  1.0  76344 40856 ?        Rs   13:13   0:00 /home/deployer/.rvm/rubies/ruby-2.6.3/bin/ruby /home/deployer/.rvm/gems/ruby-2.6.3/bin/bundle exec sidekiq -i 1 -e staging
deployer   695  0.0  0.0  10472   936 pts/0    S+   13:13   0:00 grep --color=auto sidekiq
deployer 32744 42.2  1.4 111100 56188 ?        Rs   13:13   0:02 /home/deployer/apps/app-staging/shared/bundle/ruby/2.6.0/bin/sidekiq -i 2 -e staging

但几秒钟后,它就会消失。

如果我从服务器运行 RAILS_ENV=staging bundle exec sidekiq - Sidekiq 正在运行。但是第二次我重新启动服务器/部署新代码,Sidekiq 进程被杀死。

以下是我在 Sidekiq 的 rake 任务:
namespace :sidekiq do
  desc "Tells Sidekiq (with signal TSTP) it will be shutting down at some point in the near future."\
  " It will stop accepting new work but continue working on current messages"
  task :quiet do
    on roles(:app) do
      puts capture("pgrep -f 'sidekiq' | xargs kill -TSTP")
    end
  end

  desc "Signals that Sidekiq should shut down within the -t timeout option given at start-up (see config/sidekiq.yml)."\
  " It will stop accepting new work, but continue working on current messages (as with USR1)."\
  " Any workers that do not finish within the timeout are forcefully terminated"\
  " and their messages are pushed back to Redis to be executed again when Sidekiq starts up. "
  task :terminate_gracefully do
    on roles(:app) do
      puts capture("pgrep -f 'sidekiq' | xargs kill -TERM")
    end
  end


  desc "Starts sidekiq workers. Fails if there are already running processes."
  task :start do
    on roles(:app) do
      pids =  capture("pgrep -f 'sidekiq'; true")
      puts "Present sidekiq process pids #{pids}"
      if pids.split("\n").count == 1
        # For each worker service with index ID is called
        execute "sudo service sidekiq start index=1"
        execute "sudo service sidekiq start index=2"
      else
        puts "##------------------------------------------------------------------##"
        puts "Sidekiq was not terminated before start execution. Wait untils it is finished and start it again (or kill the processes)."
        puts "##------------------------------------------------------------------##"
      end
    end
  end

  task :restart do
    invoke "sidekiq:terminate_gracefully"
    invoke "sidekiq:start"
  end
end

为什么 Capistrano 没有自动启动 Sidekiq v6?

最佳答案

Sidekiq 6.0 不再依赖守护进程,请参阅重大更改:
https://github.com/mperham/sidekiq/blob/master/Changes.md#60

BREAKING CHANGE Remove the daemonization, logfile and pidfile arguments to Sidekiq. Use a proper process supervisor (e.g. systemd or foreman) to manage Sidekiq. See the Deployment wiki page for links to more resources.



查看此主题如何使用 sidekiq 6.0 正确设置 systemd:
https://github.com/seuros/capistrano-sidekiq/issues/224

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

关于ruby-on-rails - 将 Sidekiq 升级到 v6 后,它不会在生产环境中自动启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60831870/

相关文章:

Ubuntu 服务器上的 Mysql 服务器比 Ubuntu 桌面慢

ruby-on-rails - Rails I18n : Better way of interpolating links?

ruby-on-rails - Rails 5 + postgresql 多个字段的表引用关系

javascript - 从 Google map 中删除控件

ruby - 如果存在,则从字符串中删除前导引号和尾随引号

ruby-on-rails - 在 Rails 中进行通知

ruby - 如何将 gem 依赖项添加到我的 ruby​​ gem

c++ - Ubuntu Make 文件错误

node.js - 无法在 docker 容器中安装 Node 10.x 版本

ruby-on-rails - Carrierwave 未使用 rmagick 调整版本大小