From 5a39a6563da93300b4bc150901f6d9b596298127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Javier=20Cravero?= Date: Sat, 9 Mar 2013 19:10:59 -0300 Subject: [PATCH] Added support for many Sidekiq instances on the upstart script. --- examples/upstart/manage-many/README.md | 57 +++++++++++++++++++ .../upstart/manage-many/sidekiq-manager.conf | 33 +++++++++++ examples/upstart/manage-many/sidekiq.conf | 57 +++++++++++++++++++ .../upstart/{ => manage-one}/sidekiq.conf | 0 .../upstart/{ => manage-one}/workers.conf | 0 5 files changed, 147 insertions(+) create mode 100644 examples/upstart/manage-many/README.md create mode 100644 examples/upstart/manage-many/sidekiq-manager.conf create mode 100644 examples/upstart/manage-many/sidekiq.conf rename examples/upstart/{ => manage-one}/sidekiq.conf (100%) rename examples/upstart/{ => manage-one}/workers.conf (100%) diff --git a/examples/upstart/manage-many/README.md b/examples/upstart/manage-many/README.md new file mode 100644 index 00000000..097bcf6d --- /dev/null +++ b/examples/upstart/manage-many/README.md @@ -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. diff --git a/examples/upstart/manage-many/sidekiq-manager.conf b/examples/upstart/manage-many/sidekiq-manager.conf new file mode 100644 index 00000000..864798b4 --- /dev/null +++ b/examples/upstart/manage-many/sidekiq-manager.conf @@ -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 diff --git a/examples/upstart/manage-many/sidekiq.conf b/examples/upstart/manage-many/sidekiq.conf new file mode 100644 index 00000000..0db07559 --- /dev/null +++ b/examples/upstart/manage-many/sidekiq.conf @@ -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 < /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 diff --git a/examples/upstart/sidekiq.conf b/examples/upstart/manage-one/sidekiq.conf similarity index 100% rename from examples/upstart/sidekiq.conf rename to examples/upstart/manage-one/sidekiq.conf diff --git a/examples/upstart/workers.conf b/examples/upstart/manage-one/workers.conf similarity index 100% rename from examples/upstart/workers.conf rename to examples/upstart/manage-one/workers.conf