Friday, October 9, 2009

Run JBoss in background using Capistrano

I had a very hard time to start JBoss as background process using Capistrano. At the I end I found the solution which is so simple. The important point is in you capfile don't execute the commmad with both nohup and ampersand (&). At first create start.sh file that will call run.sh to start the jboss.


The content of start.sh:


/opt/jboss-4.2.3.GA/bin/run.sh &


And in your capfile:


desc "start jboss server"
task :start_jboss do
  set :use_sudo, true
  set :user, prompt("User to run 'service jboss-frengine start' command: ")
  run "nohup /opt/jboss-4.2.3.GA/bin/start.sh" # ONLY NOHUP IS USED, DON'T USE AMPERSAND HERE
end


Make sure the user has permission to write into nohup.out

1 comment:

Uptake said...

You need to nohup and be sure to duplicate std error to std out.

The key is the 2>&1

ie.

run "RAILS_ENV=#{rails_env} nohup path/to/script < /dev/null > path/to/your/log.log 2>&1 &"