Skip to content

Instantly share code, notes, and snippets.

@Loriowar
Last active May 14, 2023 13:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Loriowar/fdf8a379ba820de9dd55c97b6fa10594 to your computer and use it in GitHub Desktop.
Save Loriowar/fdf8a379ba820de9dd55c97b6fa10594 to your computer and use it in GitHub Desktop.
Systemd unit for multiprocess sidekiq. Based on example unit from official sidekiq page on GitHub.
# https://github.com/mperham/sidekiq/blob/master/examples/systemd/sidekiq.service
#
# systemd unit file for CentOS 7, Ubuntu 15.04
#
# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Run:
# - systemctl enable sidekiq
# - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process. Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description="(sidekiq-%i) process of GettUI dev env"
# start us only once the networkm logging subsystems and redis server are available
After=syslog.target network.target redis-server.service
# See these pages for lots of options:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html
[Service]
Type=simple
WorkingDirectory=/var/www/project_name/current
# NOTE:
# - on multiprocess system potentially we can use 'taskset -c'
# - in case of split queues across processes we can add %i to confg name
ExecStart=/home/deploy/.rvm/bin/rvm 2.4.6@gett do bundle exec sidekiq --index %i --environment dev --config /var/www/project_name/current/config/sidekiq.yml
User=deploy
Group=sudo
UMask=0002
# Memory management
MemoryAccounting=true
MemoryHigh=35%
MemoryMax=50%
# 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
# NOTE: %i can be added to config name too, or you can use jornalctl for this purpose and drop below two lines
# output goes to
StandardOutput=/var/www/project_name/shared/log/sidekiq.log
StandardError=/var/www/project_name/shared/log/sidekiq.log
# Prefix for log line in case of StandardOutput/StandardError equal to syslog, journal or kmsg
SyslogIdentifier=sidekiq-%i
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment