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.
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:
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.
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.
I have been developing applications for mobile devices going on about 6 years now. I started out developing applications for a major medical information company here in Kansas City by the name of Cerner. Our platform was PocketPC, and from a development stand point it was nice, not that bad, but just not that powerful. There where limitations on the device that we encountered and had to overcome on a near daily basis. In the end however we successfully created a suite of applications that is in use today and doing quite well. My role was in this case to build most of the low level foundations that where used by the other developers. This sounds simple but frankly speaking it isn’t I had to in most cases devise from scratch many things that in my mind should be facilitated by the OS, but in pocketPC at the time they where not there.
I next moved on to PalmOS. I worked for a company that was targeting the trucking industry. Palm OS was about as bare bones as one could imagine, but it allowed for those of us interested in computer science and why we optimize our code a unique opportunity to explore that side of our skill set. Translation, the devices where very underpowered and so everything had to run as efficiently as possible to ensure that the user experience was not compromised. The result was we abandoned the projects and platform because well the target audience didn’t see the use and it would not fit in their business and second the applications we created where so complex they would be unusable.
Having developed on both of these there is one major problem that both devices share: designing a usable UI is extremely difficult. The stylus interface is terrible, and the screen is not big enough to build anything that needs large amounts of data. Next, each OS is very limited. Most of the applications I wrote needed to be asynchronous and networked. This meant multiple threads of execution and network connectivity when it was present. Let me just say this worked some of the time, and usually, when you did one thing you got locked out of something else. The last application I wrote for the mobile platform was on a pocketPC phone I carried for work. I used .NET and actually in very few lines I produced an application that connected to a bluetooth GPS downloaded position data and when a network became present the data would be uploaded to a web service where it was rendered(http://vinnyt.org/location/v3/) this worked pretty well but I ran into the same headaches I hit before network didn’t work all that well and the multi-threading was poor.
I firmly believe that the iPhone will solve these problems and it is going to be the future of mobile computing. To start with the OS is Unix under the hood this is hands down the future of computing. It has been the past and I believe that in the years to come it will continue to advance and evolve. With it you get multi-threading that will scale, you get robust networking and a rich API set that will take care of most of the problems that we as mobile developers encounter. The iPhone UI is very intuitive and with a bit of forethought the UI constructs provided will lead to some very interesting and great applications. I believe that in the next few years we are going to see the market share of this device expand nearly exponentially… Mark my words.
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.
This summer I had an opportunity to be in a film called “Stay the Same Never Change”. It was made by Laurel Nakadate. I am still not clear on my role, here is a poster for the film. I really appreciate being given the chance to participate in this film.