Skip to content

Instantly share code, notes, and snippets.

@oshanz
Forked from stevensona/delayed_job@.service
Created January 6, 2020 12:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshanz/364524f059051222adf1c14aefb54a9e to your computer and use it in GitHub Desktop.
Save oshanz/364524f059051222adf1c14aefb54a9e to your computer and use it in GitHub Desktop.
systemd unit file for running ruby/rails delayed_job as service
# Keep delayed job workers running using systemd on ubuntu
# Usage
# Start "sudo systemctl start delayed_job@{0..3}" to start 4 worker instances
# Enable "sudo systemctl enable delayed_job@{0..3}" to enable 4 worker instances
# Restart "sudo systemctl restart delayed_job@{0..3}" to restart 4 worker instances
# Disable "sudo systemctl disable delayed_job@{0..3}" to disable 4 worker instances
# Stop "sudo systemctl stop delayed_job@{0..3}" to stop 4 worker instances
[Unit]
Description=Delayed Job Worker %i
After=syslog.target network.target
AssertPathExists=/var/www/app
[Service]
Type=simple
WorkingDirectory=/var/www/app
ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec rake jobs:work'
KillSignal=SIGINT
User=deploy
Group=deploy
UMask=0002
# Restart after 1 minute delay
Restart=on-failure
RestartSec=60
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=dj_worker_%i
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment