Search code examples
ruby-on-railsrubysidekiqsystemd

Sidekiq 6 only does polling when I enter web console


I really don't know why but my sidekiq seems to stop working after a while.

However, if I

  • open the web console /sidekiq
  • login the server by ssh and ps aux | grep sidekiq once I do one of the above two things, sidekiq begin to poll immediately

My environment is

  • Sidekiq 6.2.1
  • Ubuntu20.04
  • Rails 6.1.3.1

I use systemd and capistrano-sidekiq to control sidekiq, can anyone help me?

# config/sidekiq.yaml
:queues:
  - default
  - order-jobs

This is the ~/.config/systemd/user/sidekiq.service I write:

[Unit]
Description=sidekiq
After=syslog.target network.target

[Service]
Type=notify
WatchdogSec=10

WorkingDirectory=/path/to/my/app/current

ExecStart=/home/my_username/.rvm/bin/rvm in /path/to/my/app/current do bundle exec sidekiq -e production
ExecReload=/usr/bin/kill -TSTP $MAINPID

# Greatly reduce Ruby memory fragmentation and heap usage
# https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
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=default.target

Solution

  • The user services of systemd turn out that they only live while the user has a login session. The service will stop once the last session finishes. So that's why my sidekiq, which is run by the user service, stops everytime after I logout. we can simply use loginctl enable-linger username to create a continuing existing session of the user.