Sinatra is a terrific light-weight Ruby web framework built on top of Rack. I call it a web framework, but to me it's really a services framework. I'm using it at work to build up little web services that can be consumed by other applications within our organization. If you're just looking for the rackup file, skip to the bottom of this post. For the uninitiated, here's a little bit about why Sinatra is awesome.
I prefer Sinatra to Rails for building up light weight services for a number of reasons. First, it's really simple. At under 2k loc it's easy to dig through the code and find out how things work. Writing services is as simple as having a single file with some calls like so:
get '/users/:id' do
post '/users' do
# create a user
put '/users/:id' do
# update a user
delete '/users/:id' do
# delete a user
Second, it's fast and includes only the basic stuff you need to get a web service running. This is perfect when you're designing a service that doesn't have that many entry points. The services I'm building are primarily data driven. They don't render html. They just respond with JSON while wrapping various bits of business logic. I've found that Sinatra excels in this area. The code bases are small, easy to understand, and easy to adapt.
For my services, I've decided on Passenger as the deployment platform. I had a bit of trouble getting things going at first. The example in the Sinatra documentation seems to be a little dated. To get a Sinatra app running on Passenger, you have to follow the basics for getting a Rack app up. This means that at a minimum you need to have a project with the following structure:
Since it's a Sinatra app you'll also need at least the basic service file. I called mine service.rb. Finally, here's what my rackup file config.ru looks like:
root_dir = File.dirname(__FILE__)
set :environment, :production
set :root, root_dir
set :app_file, File.join(root_dir, 'service.rb')
FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
The require 'service' line at the beginning loads up the service. I also enabled logging with the $stdout.reopen and $stderr.reopen lines. I ran into a few problems with some example rackup files that used STDOUT instead of $stdout to enable logging. This is working for me with Passenger 2.1.3, Rack 0.9.1, and Sinatra 0.9.1.1.