Ubuntu Intrepid - thin web server for Ruby

There are variety of options open to the sysadmin when serving Ruby applications.

One of them is thin. This is a 3rd party web server that is proxied to from the main web server (similar to mongrels in a general setup). Let's take a look at installing thin.


I am assuming you have Ruby and Rubygems installed on your Slice. If you don't, please see the Ubuntu Intrepid Ruby on Rails article.


Thin is a rubygem and so installation couldn't be easier:

sudo gem install thin

On the test Slice with a basic rubygems and Rails installation, the process installed the following gems:


Thin basics

There will be separate articles for proxying to thin from different web servers (Apache, Nginx, etc).

As such, we'll only look at the basics of thin, leaving Virtual Host configurations for later.

To determine the thin verions:

thin -v

As is often the case in the wacky world of the developer, each version has a unique name:

thin 1.0.0 codename That's What She Said

Starting and stopping

Starting thin requires your navigating to a rails app directory and issuing this command:

thin start -d

The '-d' option runs it in the background. If you omitted the '-d' option, it would act in a similar manner to the webbrick server and requires an 'open' terminal. In that case, a standard 'Ctl -C' would kill the process.

To stop thin, you don't need to worry about finding the PID or searching for something to kill:

thin stop


The default environment for thin is development. To start it in a production environment is easy:

thin start -d -e production


It would be relatively unusual for a Rails application to only need 1 ruby server; to start a cluster of 3 you would use this command:

thin start --servers 3

The output shows 3 servers being started sequentially from port 3000 (the default port).

Stopping the cluster is just as easy:

thin stop --servers 3

Again, the output is very clear: a quit signal is sent to each PID.


You can add thin to a runlevel (/etc/init.d/) with ease.

To start with you need to create the script:

sudo thin install

Then add the script to the default runlevels:

sudo /usr/sbin/update-rc.d -f thin defaults

The output confirms the process:

Adding system startup for /etc/init.d/thin ...
   /etc/rc0.d/K20thin -> ../init.d/thin
   /etc/rc1.d/K20thin -> ../init.d/thin
   /etc/rc6.d/K20thin -> ../init.d/thin
   /etc/rc2.d/S20thin -> ../init.d/thin
   /etc/rc3.d/S20thin -> ../init.d/thin
   /etc/rc4.d/S20thin -> ../init.d/thin
   /etc/rc5.d/S20thin -> ../init.d/thin


Now we need to define which (if any) of the rails applications to start on a reboot.

Just for example, assume I have a rails application located here:


I want to start 3 thin servers and be in production mode when they are started:

sudo thin config -C /etc/thin/testapp.yml -c /home/demo/public_html/testapp/  --servers 3 -e production

Have a look at the file that was created:

cat /etc/thin/testapp.yml

The contents:

pid: tmp/pids/thin.pid
timeout: 30
port: 3000
log: log/thin.log
max_conns: 1024
require: []

environment: production
max_persistent_conns: 512
servers: 3
daemonize: true
chdir: /home/demo/public_html/testapp

As you can see, there are several options that can be tweaked by hand if needed.

Note the server numbers and environment are exactly as we set them. You can, of course, add as many or as few options to the command as you require, such as port numbers and so on.

When the Slice is rebooted, the 3 thin servers will now start automatically.


As with most applications, there is more than I can go into here but please do check out all the options that are available to you:

thin --help


Thin is an established method of serving Ruby on Rails applications. I hope this introduction outlines how easy and sysadmin-friendly thin actually is.

To see how to proxy to the thin web server from Apache or Nginx, please see the next few articles.


Article Comments:

Jacky commented Tue Feb 24 14:14:51 UTC 2009:

I am not quite sure the purpose of this thin server, is it doing the same as mod_rail with apache? if that is the case what is the different of using thin and apache?

David Southard commented Wed May 13 06:19:12 UTC 2009:

Thin server replaces mongrel not apache... nginx replaces apache

Mike commented Fri Jun 26 01:06:01 UTC 2009:

Running the "sudo thin config -C" command gives me the error "No such file or directory /etc/thin/myapp.yml."

The -C switch doc says "Load options from config file"--not create a file as implied in the tutorial.

How does /etc/thin/myapp.yml get created if "-C" doesn't create, only load from an existing file?

Mike commented Fri Jun 26 01:18:47 UTC 2009:

Ah, forgot "sudo thin install"

Will commented Tue Nov 29 17:52:04 UTC 2011:

Gracias for the post! Even though its from almost three years ago it is still helpful

Marcelo commented Mon Jul 21 12:40:20 UTC 2014:

Link exchange is nothing else except it is only placing the other person's webpage link on your page at suitable place and other person will also do similar in favor of you.

Want to comment?

(not made public)


(use plain text or Markdown syntax)