I struggled to deploy sidekiq to an Ubuntu 20.04 server using the capistrano-sidekiq gem. Here are the steps I took to get it to work
Add to your Gemfile
gem 'sidekiq', '~> 6.2'
Add to the development group of your gemfile
group :development do
gem 'capistrano-sidekiq' # add this
end
Later, we will add items to your Capfile, but you should do a deployment before that so Sidekiq is installed on the server (and so can be run from the service).
cap staging deploy
You should now be able to run sidekiq from your command line
cd app/current
bundle exec sidekiq -e staging
Setup your sidekiq.service file. Here is where we have a bunch of gotcha's including:
- capistrano-sidekiq runs the service as a user service (appropriate for security reasons). This is important to know since it changes the elements of the service definition file as well as where you should place them
- you cannot just use the template system file since this includes User and Group definitions which will cause an error when launched as a user service. Make sure you comment these out.
- place your file in `~/.config/systemd/user/' - this is where systemctl will look for it
vim ~/.config/systemd/user/sidekiq.service
Use the latest template and comment out the following lines
# COMMENT THESE OUT
#User=deploy
#Group=deploy
#UMask=0002
Test your service
/usr/bin/env systemctl --user start sidekiq.service
Update your Capfile to include the capistrano-sidekiq commands.
require 'capistrano/sidekiq'
install_plugin Capistrano::Sidekiq
install_plugin Capistrano::Sidekiq::Systemd
You should now be able to deploy.
cap staging deploy