kenmac

CA Tuesday Tip: Manage JBoss as a UNIX daemon

Discussion created by kenmac on Jun 10, 2011

CA Access Control Tuesday Tip by Ken McCann, Senior Support Engineer for 6/14/2011:

Instead of running the JBoss startup script from the JBoss directory each time you want to start JBoss, you can start/stop the application server using an init.d script. Simply create a file called "/etc/init.d/jboss" and paste the following contents into it. Just make sure the "JBOSS_HOME" variable points to the correct location of JBoss. (Don't forget to chmod +x /etc/init.d/jboss)

You can then stop/start JBoss manually like this:
[font=Courier New]/etc/init.d/jboss start
/etc/init.d/jboss stop[font]

Or start JBoss automatically with the system by creating a rcX.d symlink:
[font=Courier New]ln -s /etc/init.d/jboss /etc/rc2.d/S85jboss[font]

#! /bin/sh JBOSS_HOME=/opt/jboss-4.2.3.GA start(){         echo "Starting jboss.."         # If using an SELinux system such as RHEL 4, use the command below         # instead of the "su":         # eval "runuser - jboss -c '/opt/jboss/current/bin/run.sh > /dev/null 2> /dev/null &'         # if the 'su -l ...' command fails (the -l flag is not recognized by my su cmd) try:         #  sudo -u jboss /opt/jboss/bin/run.sh > /dev/null 2> /dev/null &         cd $JBOSS_HOME/bin         $JBOSS_HOME/bin/run.sh -b 0.0.0.0 > /dev/null 2> /dev/null & } stop(){         echo "Stopping jboss.."         # If using an SELinux system such as RHEL 4, use the command below         # instead of the "su":         # eval "runuser - jboss -c '/opt/jboss/current/bin/shutdown.sh -S &'         # if the 'su -l ...' command fails try:         #  sudo -u jboss /opt/jboss/bin/shutdown.sh -S &         $JBOSS_HOME/bin/shutdown.sh -S & } restart(){         stop # give stuff some time to stop before we restart         sleep 60 # protect against any services that can't stop before we restart (warning this kills all Java instances running as 'jboss' user) #        killall java # if the 'su -l ...' command fails try:         #  sudo -u jboss killall java         start } case "$1" in   start)         start         ;;   stop)         stop         ;;   restart)         restart         ;;   *)         echo "Usage: jboss {start|stop|restart}"         exit 1 esac exit 0

Outcomes