Robust Way to Deploy a Rack Application (Sinatra)

Robust way to deploy a Rack application (Sinatra)

Nginx / Unicorn FTW!

Nginx in front to serve static files and unicorn to handle Sinatra app.

Benefits: Performance, good load balancing with unix socks and deploy/upgrade without any downtimes (you can upgrade Ruby/Nginx/Sinatra/app without downtime).

How-to : http://sirupsen.com/setting-up-unicorn-with-nginx/ .

How to ship a Sinatra application as a gem and deploy it?

Ignoring path-issues for now, here is how I solved it:

The application bundled as gem, tubemp.

A Gemfile to install and include the gemified application:

gem 'tubemp'

A config.ru which runs the gemified application, called Tubemp:

require 'rubygems'
require 'bundler/setup' # To allow inclusion via the Bundle/Gemfile
require 'sinatra' # Sinatra is required so we can call its "set"
require 'tubemp' # And include the application

# Set the environment to :production on production
set :environment, ENV['RACK_ENV'].to_sym

# And fire the application.
run Tubemp

These two files is all that is needed to make a new rack-application, which includes the
gemified Sinatra-app and as such are bootable trough e.g. nginx,
passenger or simply rackup.

Continuously run Sinatra on Apache server

This is usually due to the shell (for example bash) exiting and sending hangup or kill signals to all its child processes. To start the server in the background and shield it from the HUP signal you can use the command nohup:

    nohup - run a command immune to hangups, with output to a non-tty

For example:

nohup ruby sinatra_app.rb &

http://en.wikipedia.org/wiki/Nohup

For more robust deployment options you might want to look at something like Nginx and/or Phusion Passenger:

Robust way to deploy a Rack application (Sinatra)

How to create rack application to be used by Rails?

I got my question answered in another question:

How to read POST data in rack request

require 'json'

class Greeter
def call(env)
req = Rack::Request.new(env)
if req.post?
puts req.POST()
end
[200, {"Content-Type" => "application/json"}, [{x:"Hello World!"}.to_json]]
end
end

run Greeter.new

and use JSON.parse( req.body.read ) to parse POST data.

What's the difference between a Rack app and a Sinatra app?

I think the asker wants the merits of keeping it to just Rack.

Considering Sinatra is already an extremely thin & minimalistic veneer for typical web applications, my short answer will be: when your needs are atypical and/or spartan

when you don't even need...

  • layout/ templating - you enjoy writing out raw string http content
  • cookies and sessions - no memory, everything is one-shot default
  • methods - your app abuses the URL and HTTP VERB in crazy ass ways
  • to be modern - you have nostalgia with CGI/perl scripts in the 90s
  • any structure - your app returns time of day in text. per se.

I use Sinatra because I believe this is the lowest footprint you can really focus on business function of my apps, without dealing with web server nitty-gritties (Rails conversely is monoli-thick!) and still have an intuitive MVC-like project structure

You gain really little except code lines, and a smarmy twinkle in your eye when impressing geeks
honest.

p.s.: I maintain a nice skeleton for my own needs at http://github.com/codepants/yasumi

Sinatra/Rack Sleep until Response Ready (like Exchange ActiveSync)

You could also check out macournoyer's http://github.com/macournoyer/pusher "The Rack App that pushes" and collin's http://github.com/collin/orbited-ruby/



Related Topics



Leave a reply



Submit