How to deploy a self contained Rails application on Tomcat, painlessly!
Posted by victori
Categories: web development rails java
How to deploy a self contained Rails application on Tomcat, painlessly!'s RSS feed
[3] comments
How to deploy a self contained Rails application on Tomcat, painlessly!
Here at work we have a Postfix email server which handles all our email for multiple domains. The authentication and users are handled via the PostgreSQL database backend. To make life easy, I used Rails to scaffold a few tables in that Postfix PostgreSQL database. End result, is an easy to use interface to manage emails and domains. However, deployment isn't as fun as it could be, even with mongrel. I still have to have Rails/Ruby installed AND manage startup scripts to start the mongrel instance for my Rails MailManager application. Well JRuby to the rescue!
Here is how I created a self-contained Rails Application that can be reused in any Tomcat deployment.
I used the pure Ruby PostgreSQL implementation instead of the Java-centric ActiveRecord-JDBC solution, so I can develop using native Ruby while deploying via WAR using JRuby without any database.yml changes!
First off we want to instal GoldSpike which adds rake tasks to create WAR files.
script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike
Now I needed to implement a self-contained postgres-pr module. I implemented it as a Rails Plugin!
Create the postgres plugin
./script/generate plugin postgres
Copy the postgres pure implementation gem files to your Rails plugin
cp -rf /opt/local/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/* ./vender/plugins/postgres/lib/
Setup database.yml
I setup host as pdatabase, so on any server you deploy the WAR just add an alias to /etc/hosts ; 127.0.0.1 pdatabase
production: adapter: postgresql database: postfix username: victori password: ....... host: pdatabase
Run the rake task to build your reusable self-contained web application
rake war:standalone:create
Pretty darn easy eh?
shadoi
PostedHave you compared performance of the Native driver vs. the AR-JDBC driver? I recall Ola Bini mentioned that performance could suffer greatly when not using JDBC... I believe it was mentioned in this talk: http://drnicwilliams.com/2007/03/23/drop-rails-into-tomcat-and-it-just-works-ola-bini-on-jruby-presentation/
victori
Postedhonestly, I just care about the easy of deployment and development of the email application. For an internal application that manages email accounts with a user base of ~15 people, performance really isn't going to be a priority.
Furthermore, if performance was a consideration. I would not use rails but end up using wicket with spring/hibernate for the project.
Oh, the application behaves just fine using the postgres-pr native ruby driver. No noticeable slow downs even with a two or three concurrent users.
-Victor
victori
Postedtodo: add textile formatting for comments!