Run Rails reliably as runit services
Shell Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin Extract common code into 'bootstrap', and allow a bootstrap.user for … Mar 21, 2011
service Initial revision Dec 16, 2007
.gitignore Initial revision Dec 16, 2007
README.md Convert README to markdown and add Patreon badge Sep 9, 2017
add-ferret-server Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-haproxy Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-kirk Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-maintenance Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-memcached Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-mizuno Add mizuno Feb 11, 2013
add-mongrel Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-nginx Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-puma Add puma Jan 30, 2015
add-thin Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-thinking-sphinx Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-unicorn Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
add-varnish Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
bootstrap Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
check-port Explicitly use bash for all 'run' scripts, to prevent issues with rvm… Apr 9, 2012
ferret-server-run Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
haproxy-run Update haproxy-run for haproxy 1.6 Dec 29, 2015
kirk-run Fix shellcheck issues Apr 14, 2014
maintenance-run Fix shellcheck issues Apr 14, 2014
memcached-run Fix shellcheck issues Apr 14, 2014
mizuno-run Fix shellcheck issues Apr 14, 2014
mongrel-run Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
nginx-run Ensure SVG images are gzipped Aug 21, 2017
puma-run Run puma via bundle exec Jul 8, 2015
readlink_canonical Not all readlinks provide a '-e' option, so work around this with a t… Sep 11, 2008
thin-run Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
thinking-sphinx-run Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
unicorn-run Define RAILS_ENV centrally, in ./bootstrap Apr 14, 2014
varnish-run Set vcl_path for varnish, which is now necessary Jun 3, 2018

README.md

Support me

Runit services for heavy-duty Rails hosting

Here's a bunch of scripts for deploying a full production Rails app that runs under runit.

This scheme is currently used to run several large production Rails apps, including looktothesters.org, and it has worked very nicely for a couple of years now. More reliable than system-wide init.d scripts, and fewer permission headaches.

How to use it

Create an unprivileged user for your Rails app, then set up a system-wide Runit service to manage user-specific services for that user -- see this page for details.

All further steps assume that you are working as the unprivileged user.

Now, clone this project into the user's home directory:

cd
git clone git://github.com/purcell/rails-runit.git

Symlink your rails app's root directory to this directory with the name 'app':

ln -s ~appuser/releases/current ~/rails-runit/app

Now you can create some services:

cd ~/rails-runit
./add-mongrel 4001
./add-mongrel 4002
./add-mongrel 4003
./add-haproxy 4000
./add-nginx 4020 4000

This creates (potential) runit services under ~/rails-runit/service. Symlink them to ~/service, and runit will start them for you.

Once started, you can set your system-wide web server to proxy requests for your Rails app to port 4000 (haproxy => mongrel * 3), or to port 4020 (nginx => haproxy => mongrel * 3).

Browse to port 3998 (= haproxy port - 2) to see the haproxy status page.

You can then easily restart your app (e.g. as part of a capistrano deployment) like this:

sv restart ~/service/mongrel-*

Further "add-" and "-run" scripts are provided for varnish and ferret_server.

Status

The haproxy service assumes that the mongrels will be found on the 10 ports higher than itself.

The use of the 'production' RAILS_ENV is hard-coded, so look out for that if you try it on your own machine.

The entire scheme is subject to change -- see below.

Future plans

I'd like to rewrite all this in ruby so we can have templates for the config files in ERB, and to make the port mapping a bit more flexible. The 'run' scripts would then look up their config templates under RAILS_ROOT/config first, and fall back to ~/rails-runit/ if necessary.

It'd be nice to automatically generate monitrc fragments that could be included by a system-wide monit instance for the purposes of monitoring the app.