Sidekiq


When deploying, we get this error message:

sidekiq stderr: invalid option: --index

In short, the problem is in the new version 6 policy:

Remove the daemonization, logfile and pidfile command line arguments.

I’ve noted for years
how modern services should be managed with a proper init system.
Managing services manually is more error-prone, let your operating system do it for you. See the Deployment wiki page for options.

If earlier gem controlled daemonizing sidekiq itself, now basic functionality of the OS, for example, systemd in Ubuntu should be engaged in this activity.

Test system:

Ubuntu 18.04.4 LTS
rvm 1.29.9
rails 5.2.3
sidekiq 6.0.4
capistrano-sidekiq 1.0.2

There are 2 ways to solve this problem:

  • rollback to Sidekiq version 5
  • write a service for systemd in Ubuntu

Next, we will discuss option 2.

As an example, on a production server we work as deployer user, so you need to place the service code here:

/home/deployer/.config/systemd/user/sidekiq.service
  • My project is deployed to /home/deployer/project/current => if you have a different path, you need to change it in the service code.
  • If you use rbenv, you’ll need to replace the example command in ExecStar with yours.

After that we perform:

systemctl --user reenable sidekiq

So that the service starts when the server starts.

We need to append these lines to project/config/deploy.rb config:

set :init_system, :systemd
set :service_unit_name, "sidekiq"

That’s all, now capistrano can control sidekiq.

To run the service manually, we execute such a command on a production server:

systemctl --user restart sidekiq

or on a server where capistrano is running:

cap production sidekiq:restart

You can view the service log on the server by running:

# last 5 days
journalctl --user-unit sidekiq --since "5 days ago"
# last hour
journalctl --user-unit sidekiq --since "1h ago"
# last 100 lines
journalctl --user-unit sidekiq -n 100 --no-pager
# like tail -f
journalctl --user-unit sidekiq -f




Notes:

You may want to place the service system-wise in:

/etc/systemd/system/sidekiq.service

but in this case you will have to perform the following:

  • for the service to work from the deployer user, you need to add the following lines to the service in the [Service] section:
    User=deployer
    Group=deployer
    UMask=0002
  • need a SUDO command to manage the service:
    sudo service sidekiq restart
  • so, you need a passwordless sudo for the deployer user
  • you will also need to redefine the Sidekiq control commands for capistrano in deploy.rb
    For example:

    Rake::Task["sidekiq:restart"].clear_actions
    namespace :sidekiq do
      task :restart do
        on roles(:app) do
          execute :sudo, :systemctl, :restart, :sidekiq
        end
      end
    end

I do not get the point of it.
It’s better to use /home/%user%/.config/systemd/user/