Daemonization, running a program as Unix, for Sidekiq version 6 or later is not supported. Instead, we have to run the process as a service.
Write a script according to your bundler location, or you can modify the below code snippet and copy the snippet into `/usr/lib/systemd/system` (CentOS) or `/lib/systemd/system` (Ubuntu)
[Unit]
Description=sidekiq
After=syslog.target network.target
[Service]
Type=notify
WatchdogSec=10
WorkingDirectory=/home/deploy/apps/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, don't.
#ExecStart=/home/deploy/.rvm/wrappers/ruby-2.6.5/bundle exec sidekiq -e production
# Use `systemctl kill -s TSTP sidekiq` to quiet the Sidekiq process
# !!! Change this to your deploy user account !!!
User=deploy
Environment=MALLOC_ARENA_MAX=2
# if the script 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
Make sure you have given the correct path of your bundler for `ExecStart` in order to start the process. Save it as `sidekiq.service` and run `systemctl enable sidekiq`. Then we can manage the process using the commands `systemctl start sidekiq`, `systemctl stop sidekiq`, and `systemctl restart sidekiq`.
We can see the last 100 lines of log by using `journalctl -u sidekiq -rn 100`.