zerosum dirt(nap)

evolution through a series of accidents

zerosum dirt(nap)

Passenger <3 Sinatra

July 04, 2008 by nap · Comments

A couple people have asked me how I’m hosting the Sinatra-based pastie service we wrote in yesterday’s revised tutorial. The previous version ran on a mongrel handler frontended by nginx, but for this version I decided to try something a little different.

One of the big announcements at Railsconf last month was that Passenger (aka mod_rails) would be releasing a v2.0 with support not only for Rails applications but also for Rack, meaning that any Rack-based Ruby web framework can also run on it. Yay for deployment options, right? So anyway, I figured we’d give that a shot.

For those of you who haven’t yet mucked with it, Passenger is dead simple to setup. Run gem install passenger to pull down the gem, and execute the passenger-install-apache2-module command to build and install the Apache 2.2 module (you’ll need the proper Apache libraries to be present of course). The command output will show you how to configure Apache to load the module.

Getting Passenger to run a Sinatra-based application also turned out to be remarkably easy. All you need to do is create a regular old Rackup script. The file will need to be named and should contain all the logic necessary to initialize our app:

require 'rubygems'
require 'sinatra'

  :run => false,
  :env => ENV['RACK_ENV']

require 'toopaste'
run Sinatra.application

Place this file in the folder on your server where toopaste.rb and the views directory reside.

Next, create a public directory. This is where any static images, JavaScripts, or stylesheets would be kept (we’re not using any, in this simple example). Point your vhost’s DocumentRoot here:

<VirtualHost *:80>
  DocumentRoot /var/www/apps/toopaste/public

You might as well create a tmp directory too. You can place a restart.txt file in this directory to tell Passenger it needs to reload the app without restarting Apache (you can use this in your cap restart tasks, too).

Couldn’t be much easier. For more information on deploying other Rack-based frameworks (Merb, Camping, Ramaze, etc) and various other config options, check Passenger’s user guide.

blog comments powered by Disqus