Sidekiq is a popular background processing tool available in Ruby. It’s fast, robust and reliable compared to other solutions out there. Sidekiq run as a process outside of rails (but including the rails environment), which means it doesn’t start when you start your rails application. During development, we start sidekiq in another terminal (or tab) using the command
1 |
bundle exec sidekiq |
to run it as a daemon we use the -d option
1 |
bundle exec sidekiq -d |
To kill a sidekiq daemon, you need to do the PID of the sidekiq process. When a sidekiq process starts it enters its pid to file which can be found at
1 |
/path/to/rails/app/tmp/pid/sidekiq.pid |
So the command to stop it would be
1 |
pkill -F /path/to/rails/app/tmp/pid/sidekiq.pid |
But making it a daemon is not a good idea, as there is no code from sidekiq to restart the process when it fails or exits on its own. So in ubuntu, which is our favorite OS for the production server, we make sidekiq a systemd process.
Before we make it into a service and if you are using rvm you need to create a wrapper for systemd so that ruby with all the gems are available for it.
1 |
rvm wrapper 2.3.1 systemd bundle |
Once that is done you need to create a sidekiq.service file under your ‘/etc/systemd/system/‘. You can find the configuration file with default settings here.
So that was a bit from me on Sidekiq.Hope it helps you some way in further understanding sidekiq.