I'm experiencing issues configuring Sidekiq in my production environment. The application is a Rails 7.0.8.1 running on an Ubuntu 22.04 server, and the installed Redis version is 7.2.5. However, when starting Sidekiq, it tries to connect to an older version of Redis (6.0.16), causing it to fail.
Environment SetupSystemd Service File (/etc/systemd/system/sidekiq.service):
[Unit]Description=SidekiqAfter=syslog.target network.target[Service]Type=simpleWorkingDirectory=/home/deploy/lipepay/currentExecStart=/home/deploy/start_sidekiq.shUser=deployGroup=deployUMask=0002RestartSec=15Restart=alwaysEnvironment=REDIS_URL=redis://127.0.0.1:6379/0[Install]WantedBy=multi-user.target
Startup Script (/home/deploy/start_sidekiq.sh):
#!/bin/bash# File: /home/deploy/start_sidekiq.sh# Load Ruby version manager environmentexport PATH="$HOME/.rbenv/bin:$PATH"eval "$(rbenv init -)"# Set REDIS_URLexport REDIS_URL=redis://127.0.0.1:6379/0# Navigate to application directorycd /home/deploy/lipepay/current# Start Sidekiqexec /home/deploy/.rbenv/shims/bundle exec sidekiq -e production
Sidekiq Initializer (config/initializers/sidekiq.rb):
require 'sidekiq/cron'if Rails.env.production? schedule_file = "config/schedule.yml" if File.exist?(schedule_file) && Sidekiq.server? yaml_jobs = YAML.load_file(schedule_file) existing_jobs = Sidekiq::Cron::Job.all.map(&:name) yaml_jobs.each do |name, details| unless existing_jobs.include?(name) Sidekiq::Cron::Job.create(name: name, cron: details['cron'], class: details['class']) end end end Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } end Sidekiq.configure_client do |config| config.redis = { url: ENV['REDIS_URL'] } endend
Error LogsHere is the output from journalctl -u sidekiq:
Jun 26 17:34:27 ubuntu-2gb-hil-1 start_sidekiq.sh[348225]: You are connecting to Redis 6.0.16, Sidekiq requires Redis 6.2.0 or greaterJun 26 17:34:27 ubuntu-2gb-hil-1 start_sidekiq.sh[348225]: /home/deploy/lipepay/shared/bundle/ruby/3.3.0/gems/sidekiq-7.1.1/lib/sidekiq/cli.rb:184:in `verify_sufficient_redis_version'
Steps TakenCheck Redis Version:
redis-server --version# Output: Redis server v=7.2.5 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=d2f534f69a26fea
Verify Connection in Rails Console:
redis = Redis.new(url: ENV['REDIS_URL'])puts redis.info["redis_version"]# Output: 7.2.5
Check Dependencies in Gemfile.lock:
grep sidekiq Gemfile.lock# Output:# sidekiq (7.1.1)# sidekiq-cron (1.10.1)
Also sidekiq seems to be correctly configured:
sudo systemctl status sidekiq:
● sidekiq.service - Sidekiq Loaded: loaded (/etc/systemd/system/sidekiq.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2024-06-27 20:42:21 UTC; 8min ago Main PID: 805007 (ruby) Tasks: 11 (limit: 2252) Memory: 171.8M CPU: 3.620s CGroup: /system.slice/sidekiq.service└─805007 "sidekiq 7.1.1 lipepay [0 of 5 busy]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.015Z pid=805007 tid=hd1v INFO: Upgrade to Sidekiq Pro for mor>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.015Z pid=805007 tid=hd1v INFO: Sidekiq 7.1.1 connecting to Re>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.019Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.021Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.023Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.025Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.027Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.029Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.030Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>Jun 27 20:42:24 ubuntu-2gb-hil-1 start_sidekiq.sh[805007]: 2024-06-27T20:42:24.032Z pid=805007 tid=hd1v INFO: Cron Jobs - added job with nam>lines 1-20/20 (END)