Rails: How to restart sidekiq?

北城以北 提交于 2019-12-02 19:04:36

So after you find you proces_id, use the below command, that will stop the workers from getting new jobs, and they will finish existing jobs.

kill -USR1 [PROCESS_ID]

After that you can kill them

kill -TERM [PROCESS_ID]

Also there is a page on sidekiq/wiki about this, called Signals.

[edit]

Here is the signal page.

[edit]

Check video

Start:

$ bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log 

where -d demonize, -P pid file, -L log file.

Stop:

$ bundle exec sidekiqctl stop tmp/sidekiq.pid 0
Sidekiq shut down gracefully.

where 0 is number of seconds to wait until Sidekiq exits.

To keep the daemon running you should definitely have some good error handling in the HardWorker classes, but you can also use the command below to restart the sidekiq runners if they are not found in the system processes.

x=`ps aux | grep sidekiq | grep -v grep | awk '{print $2}'`; [ "$x" == "" ] && cd /path/to/deploy && bundle exec sidekiq -d -L /path/to/deploy/log/sidekiq.log -C /path/to/deploy/config/sidekiq.yml -e production

This basically looks for the PID using ps aux | grep sidekiq | grep -v grep | awk '{print $2}' and then stores it in variable x. Then, if it's empty, it will run a daemonized sidekiq process.

You can stick this guy into a cron job or something. But if your jobs are failing continually, you'll definitely want to figure out why.

EDIT: Added path to deploy from cron.

  1. Type in following command: ps -ef | grep sidekiq This gives process_id and other details of running sidekiq process in background.
  2. Copy process_id and use following command: kill process_id
  3. Use following command to start sidekiq again in background with -d option: bundle exec sidekiq -d -L log/sidekiq.log
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!