Java Tutorial - Java Scipt : Running JBoss as a Daemon

Java Tutorial - Java Scipt :

Running JBoss as a Daemon


This is similar to setting up the servlet container as a service. Once again, we add the jbossd script to the /etc/init.d director, then run the chkconfig command to install the script. Here’s the source for jbossd:
#!/bin/sh
#
# Startup script for JBoss.
#
# chkconfig: 2345 95 15
# description: JBoss is a J2EE EJB container.
# processname: jboss
# pidfile: /var/run/jboss.pid
# config: /usr/local/jboss/conf/default/jboss.conf
# logfile: /usr/local/jboss/log/server.log
#=====================================================================
#=== IMPORTANT NOTE:
#=== The comments above are required for the chkconfig script to work
#=== correctly. Please do not remove them. Read the man pages for
#=== chkconfig if you need to know more.
#=====================================================================
# Source function library.
# Set environment variables needed by JVM and JBoss
JAVA_HOME=/usr/java/j2sdk1.4.1_01
JBOSS_HOME=/usr/local/jboss
# Update the path with JRE and JBoss references.
PATH=$PATH:$JAVA_HOME/jre/bin:$JAVA_HOME/bin:$JBOSS_HOME/bin
#=====================================================================
# This function will be executed when the system is starting up.
#=====================================================================
start() {
# Start daemon
echo “Starting JBoss: “
su -l jboss -s /bin/bash -c “/usr/local/jboss/bin/run.sh”
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo “JBoss started!”
else
echo “JBoss failed to start!”
fi
echo
touch /var/lock/subsys/jboss
}
#=====================================================================
# This function will be executed when the system is stopping.
#=====================================================================
stop() {
# Stop daemon.
echo “Stopping JBoss: “
su -l jboss -s /bin/bash -c “/usr/local/jboss/bin/shutdown.sh”
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo “JBoss stopped!”
else
echo “Problem stopping JBoss!”
fi
echo
rm -f /var/lock/subsys/jboss
}
restart() {
echo “Stopping JBoss for restart...”
stop
sleep 15
echo “Restarting JBoss:”
start
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo “Usage:” “$0” “{start|stop|restart}\n”
exit 1
esac
exit 0
To install the script, run the following command: chkconfig -add jbossd JBoss should now be installed as a daemon (the “d” in jbossd stands for daemon) and will start up and shut down with the machine it is installed on.