Thin is a super-cool Rack app server written in Ruby. Normally you’ll run it behind a Webserver like Apache or Nginx. It’s great and I use it for most of my Rails and Sinatra Web apps. But my goals isn’t to convert you (like I was converted from Passenger). My goals is to tell you how to use it effectively in production.

Thin has plenty of docs with commands like

thin start -p 3001 -e production —threaded

That’s great for testing and development, but not for deployment. Fortunately Thin has some great options, but unfortunately it took hours of searching to find them. So here they are, all in one place. All of the following assumes you’ve already installed Thin with

gem install thin
are generally comfortable with it, and are running as root or sudo-ing.

Start your Thins on system boot

thin install

You’ll see output like the following. This will boot all your configured Thin apps every time your system starts. Or, on Debian/Ubuntu for instance, you could run /etc/init.d/thin stop|start|restart at any time.

To configure thin to start at system boot:
on RedHat like systems:
  sudo /sbin/chkconfig --level 345 thin on
on Debian-like systems (Ubuntu):
  sudo /usr/sbin/update-rc.d -f thin defaults
on Gentoo:
  sudo rc-update add thin default

Pick one of those and run it.

Configure your Thins

Place config files for all the Thin apps you want auto-started into /etc/thin/ . They’ll be YAML files, so their extentions should be .yml. Here’s an example with lots, but not all, available options. I have yet to find a comprehensive list, but they’re mostly the same as the command-line options listed by thin -h .

--- 
user: www-data
group: www-data
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 1
threaded: true
no-epoll: true
daemonize: true
socket: tmp/sockets/thin.sock
chdir: /path/to/your/apps/root
tag: a-name-to-show-up-in-ps aux

Stop/restart individual apps

Maybe it’s obvious to you, but it wasn’t to me. For a long time, if I wanted to restart one of my apps, all I knew to do was restart them all with /etc/init.d/thin restart . Eventually I figured out how to do it one at a time with

thin restart -C /etc/thin/app.yml

That’s it. Happy Thinning!