Wednesday, February 8, 2012

Running JBoss as a daemon

The advantage of running a JBoss instance as a service (or daemon) is that it will run in the background, taking advantage of the fact that the JBoss server is a non-interactive process. This way of running processes is particularly useful whenever you need to access a server through a command-line interface, deploy an application and run the server.

This procedure was done under Fedora 16 x64 and JBoss 5.1 community version.

1) Copy the file jboss_init_redhat.sh which is under $JBOSS_HOME/bin into /etc/init.d
2) You should rename it so that it represents the service you are referring to, for example jboss-dev
3) Now you should at least modify the following variables in the jboss-dev file:
#define where jboss is - this is the directory containing directories log, bin, conf etc  
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"RUNASIS"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}

#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"test-standard"}

4) Now you can run these commands to start, restart or stop the servers:
service jboss-dev start
service jboss-dev restart
service jboss-dev stop

Even when stopping JBoss through a service it may fail due to external events and we may not notice it. So, it is always recommended to check the logs...
tail -f /opt/jboss/server/test-standard/log/server.log
...as well as running services:
ps aux | grep java
If you see the process is still there then you should take the pid of that process (say 999), and kill the process with either one of these two commands: (keep in mind that -15 is a clean shutdown and -9 should be used in case the process still does not respond)
kill -15 999
kill -9 999

No comments:

Post a Comment