Skip to content

Instantly share code, notes, and snippets.

@davidwessman
Created June 14, 2017 14:11
Show Gist options
  • Save davidwessman/4f236af00981da967088d087f232b79b to your computer and use it in GitHub Desktop.
Save davidwessman/4f236af00981da967088d087f232b79b to your computer and use it in GitHub Desktop.
Systemd setup for Sidekiq with Capistrano
# Setup Sidekiq for rails on Debian
# This setup uses systemd to start via terminal but also via the deploy system Capistrano.
# The reload-task will not actually reload the service, but is used to prepare Sidekiq for shutdown
# There exists two services to allow for both staging and production environment.
# The application uses different redis databases by using different numbers to connect,
# i.e. localhost:6379/0 or :6379/1, which are set in each applications environment variables.
# Any questions about the configuration? Hit me up
# David Wessman, Lund , 2016-09-07, [email protected]
[Unit]
Description=sidekiq-production
# 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 redis.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=rails_app_path/production/current
ExecStart=/bin/bash -lc 'bundle exec sidekiq -e production'
# This command will kill the process without waiting
ExecStop=/bin/kill -TERM $MAINPID
# This process will tell sidekiq to stop accepting jobs, and prepare to shutdown
ExecReload=/bin/kill -USR1 $MAINPID
# The user running the rails application is allowed to run all these tasks as sudo without password
User=rails_user
Group=rails_user
UMask=0002
# 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-production
[Install]
WantedBy=multi-user.target
@thapakazi
Copy link

@davidwessman can you share the latest updated systemd config... USR1's seesms to be updated by SIGTSTP

ExecReload=/bin/kill -USR1 $MAINPID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment