Posts filed under 'General'

Deploy Sinatra app with Phusion Passenger+Apache+Rack

Recently I’ve taken an interest in Sinatra. This lightweight framework/DSL tool allows you to build powerful ruby based web apps with very little code and very very minimal overhead. The only headache I ran into was deployment of my application. Here are the steps I took.

First and foremost I would suggest using http://www.modrails.com/ in combination with apache. These tools allow you to deploy multiple rack based applications on a single server. Phusion passenger does a really nice job of managing resources so that you can run multiple apps and they play together nicely. You can also run legacy things like php apps on the same server with tremendous ease.

Next create you sinatra application for a quick example :

test.rb:
require 'rubygems'
require 'sinatra'

get '/' do
'Hello World'
end

EOF

To run this type “ruby test.rb” point your browser to http://host:4567 and you should see “Hello world”.

Create the following folders in the same directory as your sinatra app.
“lib”,”public”,”tmp” and “views”. Next create a file called “config.ru” this is the configuration file that Rack uses to know how to run your application. Add the following.

configu.ru:
require 'rubygems'
require 'sinatra'
Sinatra::Application.default_options.merge!(
:run => false,
:enf => :production
)
require 'test.rb'
run Sinatra::Application
EOF

This file is a very basic example and probably not suitable for all applications. A nice feature I discovered is you can check the rack configuration by issuing the command “rackup config.ru”. This will attempt to launch your application on port 9292. Simply point your browser to http://host.com:9292 and you should see Hello World. If there are any configuration errors you can fix them before deployment.

Once you are satisfied with your config.ru the next step is to get it deployed with apache + passenger phusion.

Add a VirtualHost entry to your apache configuration. The key step in this is to point the DocumentRoot to the “public” directory you created earlier i.e. /path/to/app/public. *Be sure in apache to add a directory entry to that public directory or you will get issues!*
a sample entry would look like:

ServerAdmin webmaster@mysite.com
DocumentRoot "/path/to/myapp/public"
ServerName myserver.com
ErrorLog "/var/log/error_log"
CustomLog "/var/log/access_log" common

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


A sample application directory might look similar to the following:

./
../
./.git
./app.rb
./config.ru
./lib
./publc
./tmp
./views

After adding the VirturalHost entry restart apache and you should be able to point your browswer to the URL and see “Hello World”.

A further cool benefit of using this configuration is you can restart this particular application by creating an empty file in ./tmp called “restart.txt” and this lets you restart the application with out affecting other applications you might have running. Honestly it is either to build and test the application when deployed with apache in this manner than using ruby app.rb because you can simply edit the file and issue “touch tmp/restart.txt” and you’re done. This is just a personal opinion.

Good luck

Add comment March 13th, 2009

The dead snake

I left work today and as I walked to go home I saw this poor snake dead in the grass.

1 comment August 11th, 2008

The past

So I was at the science center in St. Louis this weekend and encountered this radio in a display. Funny thing is we had this radio when I was growing up.

photo

1 comment July 24th, 2008

Call For Authors

Hello,
I have been operating this blog for some time now, but I’ve come to the realization that I can’t be the only author for this site. I’m trying to hunt down some contributing authors. If you have an interest in adding content drop me a line at vtoms@vinnyt.org.

Add comment February 17th, 2008

The Rolex Experiment

I am an avid watch collector I only purchase watches that I won’t feel bad if they are damaged ( I buy replicas ). I saw this site and thought it was interesting because I try to conceal what I wear but seeing and documenting peoples reactions sounds pretty cool.
http://rolexperiment.blogspot.com/

Add comment January 21st, 2008

The First Post of Pure Thought

I’m a typically introspective person and rarely do I allow my crazy thoughts to escape their cage and visit the work around them. However, from time to time I have ideas that seem no matter what I do I can’t contain them. Ooops this is not one of those times.

Technorati:

Add comment February 8th, 2007

going to California

if you know me I lived in California for about 9 months during the whole dot com debacle. I was fresh out of college and a hot shot, and I believed that I could go out there find a dot com get some stock options and then strike it rich. Well unfortunately I was about 1 year too late, and so I hung out worked with some idiots and as a result it didn’t work out quite like I had hoped. I spent me time that at eToys.com it was an interesting work experience we had big screen TVs, pool tables and every new video game of the day. My job there was to help develop a technology that was identical to what SOAP is today. Unfortunately due to the fact that if you had a pulse and saw a computer you could get a job in Sunny Southern California. I discovered this very quickly and upon doing so I realized the writing was on the wall and I had to get the hell out. Well my time there came and went. I often times think back to what I did and wonder what would have happened had I stay on the coast. I suppose that wondering and knowing what happen are 2 very different things, Since I don’t know I don’t dwell on it very often. I am going to be heading back out west in the next 2 weeks and I’m really excited. Although I’ll only be there for a day I’m excited to see it one more time.

Add comment January 30th, 2007

First Post 0f 2007

Well, it’s been a couple of weeks in coming but here it is. The year has started off quite right for old iVinnyt. I got some exciting news that I’m going to keep bottled up until it develops a little more, but if things come together as planned it’ll be a phenominal 2007. In addition a good friend of mine has decided to move back to Kansas City after a brief stint in a small town in california. I’ve signed up to start playing hockey again and will be hitting the ice start feb 14th. I’m very excited for this because it’ll be one of the first times I’ve played hockey since I got Lasik done on my eyes and frankly from the last time I played it has made a huge difference. Mainly just becuase I can see everything that is going on now and I’m not limited to the crappy vision that I was afforded when I was wearing contacts. That being said my eyes have become somewhat sensitive to light, and I’m particularly concerned about protecting my eyes so I’m going to start wearing a face shield. I decided to go with an oakley straight cut amber tinted visor as a means of cutting down the glare and to protect myself from stairing at a bright white surface for a good hour. I’ll keep you posted as things develop…..

Add comment January 23rd, 2007

Sitting in Tejas

So I’m in San Antonio. I’ve spent a fair time in texas and all my time here has pretty much been crap. I’m glad to finally see a different city in this state. You know my opinion is starting to change. I think I could come here and really have a good time.

Add comment December 27th, 2006

As new year approaches

I’ve always enjoyed the end of the year, mainly because I love christmas, and because only a short time later it’s my birthday. Now yes these are selfish reasons to anticipate the coming of the new year, but hey it’s my life and I can like certain time periods for whatever reason I want. That being said I’m going to lay out my nears resolutions for 2007 and believe me I’m going to stick to these like glue.

1. Getting into a consistent exercise habit
2. Read at least 1 book every 3 weeks.
3. Spend as much time as possible with family and friends.
4. Show kindness to others

That’s what I’m going to do what do you have?

Add comment December 25th, 2006

Previous Posts


Issues

Click here to lend your support to: Dog & Dentist and make a donation at www.pledgie.com !

Calendar

March 2010
M T W T F S S
« Mar    
1234567
891011121314
15161718192021
22232425262728
293031  

Posts by Month

Posts by Category

Other


Computers Blog Top Sites
Google PageRank Checker Tool
  • Kansas City, Missouri
    • overcast
    • Temp: 43°F
    • Wind Chill: 38°F
    • Humidity: 81%
    • Wind: WNW at 8 mph
    • Dew Point: 37°F
    • Barometer: 29.46" Hg (998 hPa)
    • Clouds: overcast
    • Visibility: 10 miles