GlassFish v3 Capistrano recipe:

<pre>

set :context_root, "/" # You can obviously change this if you want to
set :glassfish_location, "/path/to/your/glassfish"
namespace :deploy do
desc "Cold start Glassfish v3"
task :cold do
run "#{glassfish_location}/bin/asadmin start-domain domain1"
start
end

desc "Stop a server running Glassfish v3"
task :stop do
run "#{glassfish_location}/bin/asadmin undeploy #{current_dir} || true"
run "#{glassfish_location}/bin/asadmin stop-domain domain1"
end
desc "update and deploy to Glassfish v3"
task :start do
update
run "#{glassfish_location}/bin/asadmin deploy --contextroot #{context_root} #{deploy_to}/#{current_dir}"
end

desc "restart the application"
task :restart do

run "#{glassfish_location}/bin/asadmin deploy --force=true --contextroot #{context_root} #{deploy_to}/#{current_dir}"
end

desc "Undeploy the application"
task :undeploy do
run "#{glassfish_location}/bin/asadmin undeploy #{current_dir}"
end
end

</pre>

GlassFish v3 Gem Recipe:

<pre>
set :context_root, "/"
set :jruby_location, "/home/jacob/jruby/"
set :gf_port, "3000"
set :environment, "production"
set :jruby_runtimes, "1"
set :jruby_min_runtimes, "1"
set :jruby_max_runtimes, "1"

namespace :gem do

desc "Start Glassfish Gem from a shutdown state"
task :cold do
start
end

desc "Stop a server running Glassfish Gem"
task :stop do
run "kill INT $(cat #{current_path}/capistrano#{application})"
end

desc "Starts a server running Glassfish Gem"
task :start do
run "#{jruby_location}bin/jruby S glassfish --contextroot #{context_root} --port #{gf_port} --environment #{environment} --runtimes #{jruby_runtimes} --runtimes-min #{jruby_min_runtimes} --runtimes-max #{jruby_max_runtimes} -P #{current_path}/capistrano#{application} --daemon #{release_path}"
end

desc "Restarts a server running Glassfish Gem"
task :restart do
stop
start
end
end

</pre>