Deploying Sinatra on Passenger

Mar 6th, 2009 by joe in tech

We often make use of the great Ruby micro-framework Sinatra in our daily work.  It’s a great way to Ruby-ify a site when you don’t need all the bells and whistles that come with Rails.  To deploy a site with it though, I had to do a little bit of research, and finally came up with this small Rack recipe that I hope might help out someone trying to do the same.

require 'rubygems'
require 'path/to/sintra' # I often vendor it inside the app folder with a path like 'vendor/sinatra/lib/sinatra.rb'

set :public,   File.expand_path(File.dirname(__FILE__) + '/public') #Include your public folder
set :views,    File.expand_path(File.dirname(__FILE__) + '/views')  #Include the views
set :environment, :production

disable :run, :reload

log = File.new("/path/to/log/files/sinatra.log", "a") # This will make a nice sinatra log along side your apache access and error logs
STDOUT.reopen(log)
STDERR.reopen(log)

require 'app_name'
run Sinatra::Application

Thanks to John Nunemaker and Chris Schneider for the reference!

4 Comments

  • Any idea why my config.ru file is not being read by passenger, Apache is serving up the folder as static files.

    [code]

    ServerName update.mydomain.co.uk
    DocumentRoot /home/kris/sites/update.mydomain.co.uk/app

    [/code]

    I have passenger gem 2.0.3 and my config.ru looks like this:

    [code]
    require ’sinatra/lib/sinatra.rb’
    require ‘rubygems’

    Sinatra::Application.default_options.merge!(
    :run => false,
    :env => :production,
    :raise_errors => true
    )

    log = File.new(”sinatra.log”, “a”)
    STDOUT.reopen(log)
    STDERR.reopen(log)

    require ‘price_updater.rb’
    run Sinatra.application
    [/code]

  • Okay I worked it out, you need to add public and tmp folders and point the vhost at the public folder.

    /root/config.ru
    /root/public
    /root/tmp

    DocumentRoot /home/kris/sites/update.mydomain.co.uk/app/public

  • Nice post…Thank you for sharing some good things!!

  • could you pls note the version of sinatra this works with? Kernel#run isn’t defind for sinatra 1.0