Search code examples
ruby-on-railssidekiqsuse

How to configure Sidekiq as a service on SUSE SLES15?


It's now time to deploy my RoR 5.2.4 application to the validation environment. Inspired by this post and some other readings, I try to setup Sidekiq as a service on SLES15. Here is the service file:

#
# This file tells systemd how to run Sidekiq as a 24/7 long-running daemon.
#
# Unit file is created into /etc/systemd/system/ for execution on SLES15@BFS
# The Unit file drives only one instance of the process. To run multiple processes,
# create multiple Unit files and register multiple services
#
# Register and control service:
#   - systemctl enable sidekiq
#   - systemctl {start,stop,restart} sidekiq
#   - journalctl -u sidekiq -rn 100 (shows the last 100 lines of log output)
[Unit]
# Start the service only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
Description=sidekiq
After=syslog.target network.target redis-server.service

[Service]
# Sidekiq automatically supports systemd's `Type=notify` and watchdog service monitoring.
# If your Sidekiq process locks up, systemd's watchdog will restart it within seconds.
Type=notify
WatchdogSec=10
WorkingDirectory=/home/a80838986/sis-portal
# If you use rbenv:
ExecStart=/bin/bash -lc 'exec /home/a80838986/.rbenv/shims/bundle exec sidekiq -e validation -C /home/a80838986/sis-portal/config/sidekiq.yml'
# Use `systemctl kill -s TSTP sidekiq` to quiet the Sidekiq process

# !!! Change this to your deploy user account !!!
User=a80838986
Group=linuxusers
UMask=0002

# Greatly reduce Ruby memory fragmentation and heap usage
Environment=MALLOC_ARENA_MAX=2

# if we crash, restart
RestartSec=1
Restart=on-failure

# output goes to /var/log/syslog (Ubuntu) or /var/log/messages (CentOS)
StandardOutput=syslog
StandardError=syslog
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq

[Install]
WantedBy=multi-user.target

But this way, Sidekiq issues an error:

LOGIN[117401]:  ORIGINUSER= PPID=1
sidekiq[117376]: bundler: command not found: sis-portal/sidekiq
sidekiq[117376]: Install missing gem executables with `bundle install`
systemd[1]: sidekiq.service: Main process exited, code=exited, status=127

Never the less, ExecStart's statement executes correctly when ran from the application folder /home/a80838986/sis-portal.

How to configure this service so that Sidekiq actually works?


Solution

  • As suspected, the ExecStat statement did not find the path to bundle. I updated it giving the path with the -r option:

    ExecStart=/bin/bash -lc 'exec /home/a80838986/.rbenv/shims/bundle exec sidekiq 
        -e validation 
        -C /home/a80838986/sis-portal/config/sidekiq.yml 
        -r /home/a80838986/sis-portal'
    

    Sidekiq is now up and running, showing a green Active status on the console.