Issue
I have tired to setup sidekiq on ubuntu
This is my sidekiq.service file (wrote by this rel="nofollow noreferrer">example)
[Unit]
Description=sidekiq
After=syslog.target network.target
[Service]
Type=notify
WatchdogSec=10
WorkingDirectory=/var/www/document-draft
# WorkingDirectory=/var/www/document-draft/current -> I also tried this
ExecStart=/bundle exec sidekiq -e production
# I have also tried these commands:
# ExecStart=/sudo bundle exec sidekiq -e production
# ExecStart=bundle exec sidekiq -e production
# ExecStart=/home/deploy/.rvm/gems/ruby-2.7.1/wrappers/bundle exec sidekiq -e production
# ExecStart=/home/deploy/.rvm/bin/rvm in /opt/myapp/current do bundle exec sidekiq -e production
Environment=MALLOC_ARENA_MAX=2
RestartSec=1
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
I'm using ruby 2.7 and when I start sidekiq service
$ systemctl enable sidekiq
$ systemctl start sidekiq
I get this error
Job for sidekiq.service failed because the control process exited with error code.
See "systemctl status sidekiq.service" and "journalctl -xe" for details.
when I check logs I see this
● sidekiq.service - sidekiq
Loaded: loaded (/lib/systemd/system/sidekiq.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-04-08 05:04:21 UTC; 9s ago
Process: 150072 ExecStart=/sudo bundle exec sidekiq -e production (code=exited, status=200/CHDIR)
Main PID: 150072 (code=exited, status=200/CHDIR)
Apr 08 05:04:19 ip-172-31-29-35 systemd[1]: sidekiq.service: Main process exited, code=exited, status=200/CHDIR
Apr 08 05:04:19 ip-172-31-29-35 systemd[1]: sidekiq.service: Failed with result 'exit-code'.
Apr 08 05:04:19 ip-172-31-29-35 systemd[1]: Failed to start sidekiq.
Apr 08 05:04:21 ip-172-31-29-35 systemd[1]: sidekiq.service: Scheduled restart job, restart counter is at 5.
Apr 08 05:04:21 ip-172-31-29-35 systemd[1]: Stopped sidekiq.
Apr 08 05:04:21 ip-172-31-29-35 systemd[1]: sidekiq.service: Start request repeated too quickly.
Apr 08 05:04:21 ip-172-31-29-35 systemd[1]: sidekiq.service: Failed with result 'exit-code'.
Apr 08 05:04:21 ip-172-31-29-35 systemd[1]: Failed to start sidekiq.
I'm confused on why I cannot start sidekiq because my Gemfile has sidekiq gem and i can successfully start it manually using any of the commands I'm using in service file.
But my motive is to start is as a background service so it may not shut down.
Solution
I was able to make it run by writing my sidekiq.service job in /lib/systemd/system
using sudo vim /lib/systemd/system/sidekiq.service
# start us only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
After=syslog.target network.target
[Service]
# You may want to use
# Type=notify
# to ensure service is not marked as started before it actually did.
# Include sd_notify gem to send a message on sidekiq startup like
# Sidekiq.configure_server do |config|
# config.on(:startup) { SdNotify.ready }
# end
# to let systemd know when the service is actually started.
Type=simple
WorkingDirectory=/var/www/document-draft
# If you use rbenv:
ExecStart=/bin/bash -lc 'exec /home/ubuntu/.rbenv/shims/bundle exec sidekiq -e production'
# If you use the system's ruby:
# ExecStart=/bin/bash -lc 'exec /home/deploy/.rvm/wrappers/ruby-2.6.5@brentmark-portal/bundle exec sidekiq -e production'
# use `systemctl reload sidekiq` to send the quiet signal to Sidekiq
# at the start of your deploy process.
ExecReload=/usr/bin/kill -TSTP $MAINPID
User=ubuntu
Group=ubuntu
UMask=0002
# 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
# ERROR: Logfile redirection was removed in Sidekiq 6.0, Sidekiq will only log to STDOUT
# StandardOutput=/var/www/sites/document-draft/log/sidekiq.log
# StandardError=/var/www/sites/document-draft/log/sidekiq.log
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
After that systemctl start sidekiq
to start this service
Answered By - Muhammad Shazar Answer Checked By - Candace Johnson (WPSolving Volunteer)