mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Added support for many Sidekiq instances on the upstart script.
This commit is contained in:
parent
3f483c30a2
commit
5a39a6563d
5 changed files with 147 additions and 0 deletions
57
examples/upstart/manage-many/README.md
Normal file
57
examples/upstart/manage-many/README.md
Normal file
|
@ -0,0 +1,57 @@
|
|||
# Sidekiq as a service using Upstart
|
||||
|
||||
Manage multiple Sidekiq servers as services on the same box using Ubuntu upstart.
|
||||
|
||||
## Installation
|
||||
|
||||
# Copy the scripts to services directory
|
||||
sudo cp sidekiq.conf sidekiq-manager.conf /etc/init
|
||||
|
||||
# Create an empty configuration file
|
||||
sudo touch /etc/sidekiq.conf
|
||||
|
||||
## Managing the dojo
|
||||
|
||||
Sidekiq-enabled apps are referenced in /etc/sidekiq.conf by default. Add each app's path as a new line, e.g.:
|
||||
|
||||
```
|
||||
/home/apps/my-cool-ruby-app,1
|
||||
/home/apps/another-app/current,2
|
||||
```
|
||||
|
||||
The format is:
|
||||
|
||||
`app,number_of_workers`
|
||||
|
||||
Start the jungle running:
|
||||
|
||||
`sudo start sidekiq-manager`
|
||||
|
||||
This script will run at boot time.
|
||||
|
||||
Start a single sidekiq like this:
|
||||
|
||||
`sudo start sidekiq app=/path/to/app index=0`
|
||||
|
||||
## Logs
|
||||
|
||||
Everything is logged by upstart, defaulting to `/var/log/upstart`.
|
||||
|
||||
Each sidekiq instance is named after its directory, so for an app called `/home/apps/my-app` with one process the log file would be `/var/log/upstart/sidekiq-_home_apps_my-app-0.log`.
|
||||
|
||||
## Conventions
|
||||
|
||||
* The script expects:
|
||||
* a config file to exist under `config/sidekiq.yml` in your app. E.g.: `/home/apps/my-app/config/sidekiq.yml`.
|
||||
* a temporary folder to put the processes PIDs exists called `tmp/sidekiq`. E.g.: `/home/apps/my-app/tmp/sidekiq`.
|
||||
|
||||
You can always change those defaults by editing the scripts.
|
||||
|
||||
## Before starting...
|
||||
|
||||
You need to customise `sidekiq.conf` to:
|
||||
|
||||
* Set the right user your app should be running on unless you want root to execute it!
|
||||
* Look for `setuid apps` and `setgid apps`, uncomment those lines and replace `apps` to whatever your deployment user is.
|
||||
* Replace `apps` on the paths (or set the right paths to your user's home) everywhere else.
|
||||
* Uncomment the source lines for `rbenv` or `rvm` support unless you use a system wide installation of Ruby.
|
33
examples/upstart/manage-many/sidekiq-manager.conf
Normal file
33
examples/upstart/manage-many/sidekiq-manager.conf
Normal file
|
@ -0,0 +1,33 @@
|
|||
# /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
|
57
examples/upstart/manage-many/sidekiq.conf
Normal file
57
examples/upstart/manage-many/sidekiq.conf
Normal file
|
@ -0,0 +1,57 @@
|
|||
# /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 apps
|
||||
# setgid apps
|
||||
|
||||
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/apps
|
||||
|
||||
# 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/apps/.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
|
Loading…
Reference in a new issue