Setup redis and sidekiq service

1) Setup redis server

a) sudo apt install redis-server
b) Open this file with your preferred text editor:

sudo nano /etc/redis/redis.conf

In this file change supervised no to supervised systemd

c) sudo systemctl restart redis.service

2) Steps to setup sidekiq

1) gem “sidekiq”
2) bundle install
3) In config/application.rb add — config.active_job.queue_adapter = :sidekiq
4) touch config/initializers/sidekiq.rb
5) Add the following in sidekiq.rb
idekiq_config = { url: “redis://localhost:6379/0” }
Sidekiq.configure_server do |config|
config.redis = sidekiq_config
end

Sidekiq.configure_client do |config|
config.redis = sidekiq_config
end

6) touch “config/sidekiq.yml”
7) Add the following in sidekiq.yml
development:
:concurrency: 1
production:
:concurrency: 1
:queues:
— default

8) test using the command — bundle exec sidekiq -e development -C config/sidekiq.yml
9) Add the following in routes — require ‘sidekiq/web’
mount Sidekiq::Web => ‘/sidekiq’

Access sidekiq web using /sidekiq

3) Setup sidekiq as service on linux server

1) cd /etc/systemd/system

2) sudo touch sidekiq.service

3) sudo nano sidekiq.service and add the following and change application path and rbenv library path accordingly

[Unit]
Description=sidekiq
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/ganesh_prasad/projects/project_name
# If you use rbenv:
# ExecStart=/bin/bash -lc ‘exec /home/deploy/.rbenv/shims/bundle exec sidekiq -e production’
# If you use the system’s ruby:
# ExecStart=/usr/local/bin/bundle exec sidekiq -e production
# If you use rvm in production without gemset and your ruby version is 2.6.5
# ExecStart=/home/deploy/.rvm/gems/ruby-2.6.5/wrappers/bundle exec sidekiq -e production
# If you use rvm in production with gemset and your ruby version is 2.6.5
# ExecStart=/home/deploy/.rvm/gems/ruby-2.6.5@gemset-name/wrappers/bundle exec sidekiq -e production
# If you use rvm in production with gemset and ruby version/gemset is specified in .ruby-version,
# .ruby-gemsetor or .rvmrc file in the working directory
#ExecStart=/home/deployer/.rvm/bin/rvm in /path/to/your/app/current do bundle exec sidekiq -e production
ExecStart=/bin/bash -lc ‘/home/ganesh_prasad/.rbenv/shims/bundle exec sidekiq -e production -C /home/ganesh_prasad/projects/project_name/config/sidekiq.yml’
User=ganesh_prasad
Group=ganesh_prasad
UMask=0002
Environment=MALLOC_ARENA_MAX=2
# if we crash, restart
RestartSec=1
Restart=on-failure
# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog
# This will default to “bundler” if we don’t specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target

4) Reload the service using command
sudo systemctl daemon-reload

5) Enable sidekiq service
sudo systemctl enable sidekiq.service

6) Start sidekiq
sudo service sidekiq start
7) Check systemlog
sudo cat /var/log/syslog
8) Check if sidekiq is running
sudo ps aux | grep sidekiq
sudo systemctl status

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store