Skip to content

Instantly share code, notes, and snippets.

@chaitu87
Created March 7, 2014 08:52
Show Gist options
  • Save chaitu87/9407937 to your computer and use it in GitHub Desktop.
Save chaitu87/9407937 to your computer and use it in GitHub Desktop.
Deploying Sidekiq on Ubuntu - Production
# /etc/init/sidekiq-manager.conf - manage a set of Sidekiqs
# This example config should work with Ubuntu 12.04+. It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See sidekiq.conf for how to manage a single Sidekiq instance.
#
# Use "stop workers" to stop all Sidekiq instances.
# Use "start workers" to start all instances.
# Use "restart workers" to restart all instances.
# Crazy, right?
#
description "Manages the set of sidekiq processes"
# This starts upon bootup and stops on shutdown
start on runlevel [2345]
stop on runlevel [06]
# Set this to the number of Sidekiq processes you want
# to run on this machine
env SIDEKIQ_CONF=/etc/sidekiq.conf
pre-start script
for i in `cat $SIDEKIQ_CONF`; do
app=`echo $i | cut -d , -f 1`
num_workers=`echo $i | cut -d , -f 2`
for j in `seq 0 $(($num_workers - 1))`; do
start sidekiq app=$app index=$j
done
done
end script
# /etc/init/sidekiq.conf - Sidekiq config
# This example config should work with Ubuntu 12.04+. It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Sidekiq instances at once.
#
# Save this config as /etc/init/sidekiq.conf then mange sidekiq with:
# sudo start sidekiq app=/path/to/app index=0
# sudo stop sidekiq app=/path/to/app index=0
# sudo status sidekiq app=/path/to/app index=0
#
# or use the service command:
# sudo service sidekiq {start,stop,restart,status}
#
description "Sidekiq Background Worker"
# no "start on", we don't want to automatically start
stop on (stopping sidekiq-manager or runlevel [06])
# change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
setuid ubuntu
setgid ubuntu
respawn
respawn limit 3 30
instance ${app}-${index}
script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash <<EOT
# uncomment to use syslog for logging
# exec &> /dev/kmsg
export HOME=/home/ubuntu
# Pick your poison :) Or none if you're using a system wide installed Ruby.
# rbenv
# source /home/apps/.bash_profile
# OR
# source /home/apps/.profile
# OR system:
# source /etc/profile.d/rbenv.sh
#
# rvm
source /home/ubuntu/.rvm/scripts/rvm
logger -t sidekiq "Starting process: $app-$index"
cd $app
exec bundle exec sidekiq -i ${index} -e production -C config/sidekiq.yml -P tmp/sidekiq/${index}.pid
EOT
end script
pre-stop script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash <<EOT
# uncomment to use syslog for logging
# exec &> /dev/kmsg
export HOME=/home/ubuntu
# Pick your poison :) Or none if you're using a system wide installed Ruby.
# rbenv
# source /home/apps/.bash_profile
# OR
# source /home/apps/.profile
# OR system:
# source /etc/profile.d/rbenv.sh
#
# rvm
source /home/ubuntu/.rvm/scripts/rvm
logger -t sidekiq "Stopping process: $app-$index"
cd $app
exec bundle exec sidekiqctl stop tmp/sidekiq/${index}.pid
EOT
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment