Rails: How to restart sidekiq?

44,002

Solution 1

So after you find you PID, you can use the below commands: the first will stop the workers from getting new jobs and will let existing jobs complete:

kill -USR1 [PID]

after that, you can kill the process using:

kill -TERM [PID]

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

[edit]

Here is the signal page.

[edit]

Check video

For finding PIDs one can use:

ps aux | grep sidekiq

Solution 2

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.

Solution 3

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.

Solution 4

  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
Share:
44,002
Can Can
Author by

Can Can

Updated on December 03, 2021

Comments

  • Can Can
    Can Can over 2 years

    I am using sidekiq gem to run API calls in background. I ran sidekiq in Daemon process like:

      bundle exec sidekiq -d
    

    Now I made some changes in my method, so I want to restart sidekiq. I tried to kill the sidekiq by using the below command:

      kill -9 process_id 
    

    but it's not working. I want to know the command to restart sidekiq process. If you have any idea please share with me.

    I tried the below command also:

     sidekiqctl stop /path/to/pid file/pids/sidekiq.pid
    
  • Phan Hai Quang
    Phan Hai Quang over 2 years
    This does not work with Sidekiq 6.0. Error messages are ERROR: Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services ERROR: PID file creation was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services ERROR: Logfile redirection was removed in Sidekiq 6.0, Sidekiq will only log to STDOUT