Current Articles | RSS Feed
Now we'll deploy a Ruby on Rails application (we'll use a ready-to-deploy Rails application, Radiant, that drops into this environment easily) into a production-ready JRuby on Rails environment running GlassFish. This tutorial does not cover tuning any parameters, but focuses rather on getting the server installed and running, and successfully deploying a Rails application into the GlassFish container.
We will use a RedHat ES 5 server for this tutorial. We've chosen the latest stable binary of JRuby 1.1.5 and we will use GlassFish v2. I think that's all we need to know before we jump into the ...
export JRUBY_HOME=/usr/local/jrubyexport PATH=$PATH:$JRUBY_HOME/bin
[freddy@wazi]# jruby -vjruby 1.1.5 (ruby 1.8.6 patchlevel 114) (2008-11-03 rev 7996) [amd64-java]
system-level executable commands
jruby -S
[freddy@wazi]# jruby -S gem install rubygems-update[freddy@wazi]# jruby -S update_rubygems[freddy@wazi]# jruby -S gem install jruby-openssl[freddy@wazi]# jruby -S gem install rails activerecord-jdbcmysql-adapter warbler
[freddy@wazi]# jruby -S rails -v Rails 2.2.2
We are going to use Radiant CMS for some simple testing, so let's install and setup Radiant...
[freddy@wazi]# jruby -S gem install radiant[freddy@wazi]# jruby -S radiant --database mysql /usr/local/wazi-radiant[freddy@wazi]# mysqladmin create wazi-radiant_productionWe are not going to set up any security for the MySQL instance; that's a different topic altogether. For this reason, a local MySQL server in conjunction with the root user should work.
[freddy@wazi]# jruby -S gem install radiant[freddy@wazi]# jruby -S radiant --database mysql /usr/local/wazi-radiant[freddy@wazi]# mysqladmin create wazi-radiant_production
=> /usr/local/wazi-radiant/config/database.yml <=
production:adapter: mysqldatabase: wazi-radiant_productionusername: rootpassword:host: localhost
That should do it for the configuration, now let's bootstrap the application:
[freddy@wazi /usr/local/wazi-radiant]# jruby -S rake production db:bootstrap
This task will destroy any data in the database. Are you sure you want tocontinue? [yn] y
= 1 CreateRadiantTables: migrating ==========================================Create the admin user (press enter for defaults).Name (Administrator):Username (admin):Password (radiant):Select a database template:1. Empty2. Simple Blog3. Styled Blog[1-3]: 3Creating Pages....OKCreating Layouts....OKCreating Snippets....OKCreating Page parts....OKFinished.
Now, let's run a quick test to see if everything is where it should be. We will start WEBrick and open a test page:
jruby -S script/server -e production -p 4444
=> Booting WEBrick...=> Rails application started on http://0.0.0.0:4444=> Ctrl-C to shutdown server; call with --help for options[2008-11-19 16:29:03] INFO WEBrick 1.3.1[2008-11-19 16:29:03] INFO ruby 1.8.6 (2008-11-03) [java][2008-11-19 16:29:03] INFO WEBrick::HTTPServer#start: pid=3359 port=4444
Pointing the browser to http://localhost:4444/ should now result in a nice looking blog interface, with an admin section available at http://localhost:4444/admin.Now, let's install and configure GlassFish so that we can deploy this application in a Java engine.
http://localhost:4444/
http://localhost:4444/admin
To install and configure GlassFish, you need to have JDK v5 or JDK v6 installed on your system. For this demo we are using JDK1.6.0_02-b05.You can download the Glassfish v2-ur1-b09d installer from OLEX here http://olex.openlogic.com/packages/glassfish. And here are the instructions for running the installer:
Make sure your JAVA_HOME is set to a JDK![freddy@wazi]# java -Xmx256m -jar filename.jar[freddy@wazi]# mv glassfish /usr/local/[freddy@wazi]# cd /usr/local/glassfish[freddy@wazi]# chmod -R +x lib/ant/bin[freddy@wazi]# lib/ant/bin/ant -f setup.xmlWe are waiting for BUILD SUCCESSFUL
Now you can move the Glassfish directory where you would like your Glassfish installation to live. ( Like /usr/local/glassfish )Now cd into the glassfish directory and start the server...[freddy@wazi]# bin/asadmin start-domain
[freddy@wazi]# bin/asadmin start-domain
...
Domain listens on at least following ports for connections:[8080 8181 4848 3700 3820 3920 8686 ].Domain does not support application server clusters and other standalone instances.
You should now be able to access the GlassFish admin screen at http://localhost:4848, and the GlassFish landing page at http://localhost:8080/. The username/password for the admin console is admin/adminadmin.We will now use Warbler to package our application into a war file, but we will need to setup the warble.rb configuration file first. First, we should create a generic configuration file for warbler. Strictly speaking, you don't "need" a wrble.rb file, BUT it makes the process a lot easier, so we recommend it.
http://localhost:4848
http://localhost:8080/. The username/password for the admin console is admin/adminadmin.
. The username/password for the admin console is admin/adminadmin.
warble.rb
wrble.rb
[freddy@wazi]# jruby -S warble config
The warble.rb file has a few issues with the Radiant gem, so we have to edit the file:
gem
=> config/warble.rb <=
Warbler::Config.new do |config|config.staging_dir = "tmp/war"config.dirs = %w(config log vendor tmp)config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]require "#{RAILS_ROOT}/config/boot"BUILD_GEMS = %w(warbler rake rcov)for gem in Gem.loaded_specs.valuesnext if BUILD_GEMS.include?(gem.name)config.gems[gem.name] = gem.version.versionendconfig.gem_dependencies = trueconfig.webxml.rails.env = ENV['RAILS_ENV'] || 'production'end[freddy@wazi /usr/local/wazi-radiant]# jruby -S warble[freddy@wazi /usr/local/wazi-radiant]# ls *.warwazi-radiant.war
We now have a .war file that is deployable, so let's push that to our running GlassFish server:
[freddy@wazi /usr/local/wazi-radiant]# ../glassfish/bin/asadmin deploy --contextroot / wazi-radiant.war
Command deploy executed successfully.
Now our Radiant application can be accessed via http://localhost:8080/.This was a very high level tutorial geared to get you up and running fast using Glassfish as your production Ruby on Rails server. We used a ready-to-deploy Rails application, Radiant, that drops into this environment easily and shows something 'real' when the process is completed.
http://localhost:8080/
Allowed tags: <a> link, <b> bold, <i> italics