Deploying a Merb app on Glassfish with Capistrano
December 4th, 2008A lot shorter than the last post with a lot less weirdness.
I have traditionally (can you say that for something you’ve used barely a year?) used Capistrano to deploy my Rails applications. Most of the time to a pack of Mongrel but lately all Phusion Passenger. So the natural thing to do when looking to deploy a Merb app into production was dusting of Capistrano.
Long story short, my deploy.rb file( (without all the usual stuff):
set :warfile_name, "calculator"
role :app, "85.17.94.1"
role :web, "85.17.94.1"
role :db, "85.17.94.1", :primary => true
namespace :deploy do
desc "Create WAR file after deploy and deploy that WAR file"
task :after_update_code do
run "cd #{release_path}/ && MERB_ENV=production warble"
end
task :stop do
run "/usr/local/glassfishv3-prelude/bin/asadmin undeploy #{warfile_name}"
end
task :start do
run "/usr/local/glassfishv3-prelude/bin/asadmin deploy --contextroot / #{release_path}/#{warfile_name}.war"
end
task :restart do
run "/usr/local/glassfishv3-prelude/bin/asadmin redeploy --name #{warfile_name} #{release_path}/#{warfile_name}.war"
end
end
Many thanks to the BrightLight blog for providing the initial inspiration.
Note the explicit MERB_ENV environment variable, this makes sure that, well you guessed it, build the WAR file with the production config file. The remainder is stupidly easy once you have figured it out.
There was one thing which threw a spanner in the works. When I was testing with (re)deploying etc I ran into a nasty ‘Permgen space’ Java error. I still hardly know what it does but apparently if you start your Glassfish server with the switch ‘-XX:MaxPermSize=256m’ everything should work fine again. No guarantees.