[jboss-user] [Beginners Corner] - How to run JBoss as a service/daemon in RedHat?

socal_javaguy do-not-reply at jboss.com
Mon Jul 27 20:20:47 EDT 2009


I am using JBoss 5.1.0 GA on Red Hat (Amazon ECS)...

Am trying to set it up so JBoss will run as a service / daemon (right now it only starts up when I manually SSH and invoke sh $JBOSS_HOME/bin/run.sh).

Here's what I did so far:

(1) Created the following jboss script in /etc/init.d/:


  | #define where jboss is - this is the directory containing directories log, bin, conf etc
  | JBOSS_HOME=${JBOSS_HOME:-"/usr/jboss-5.1.0.GA"}
  | 
  | #define the user under which jboss will run, or use 'RUNASIS' to run as the current user
  | JBOSS_USER=${JBOSS_USER:-"jboss"}
  | 
  | #make sure java is in your path
  | JAVAPTH=${JAVAPTH:-"/usr/java/jdk/bin"}
  | 
  | #configuration to use, usually one of 'minimal', 'default', 'all'
  | JBOSS_CONF=${JBOSS_CONF:-"default"}
  | 
  | #if JBOSS_HOST specified, use -b to bind jboss services to that address
  | JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
  | 
  | #define the classpath for the shutdown class
  | JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
  | 
  | #define the script to use to start jboss
  | JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
  | 
  | if [ "$JBOSS_USER" = "RUNASIS" ]; then
  |   SUBIT=""
  | else
  |   SUBIT="su - $JBOSS_USER -c "
  | fi
  | 
  | if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  |   # ensure the file exists
  |   touch $JBOSS_CONSOLE
  |   if [ ! -z "$SUBIT" ]; then
  |     chown $JBOSS_USER $JBOSS_CONSOLE
  |   fi 
  | fi
  | 
  | if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  |   echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  |   echo "WARNING: ignoring it and using /dev/null"
  |   JBOSS_CONSOLE="/dev/null"
  | fi
  | 
  | #define what will be done with the console log
  | JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
  | 
  | JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
  | JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}
  | 
  | if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  |   export PATH=$PATH:$JAVAPTH
  | fi
  | 
  | if [ ! -d "$JBOSS_HOME" ]; then
  |   echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  |   exit 1
  | fi
  | 
  | echo JBOSS_CMD_START = $JBOSS_CMD_START
  | 
  | case "$1" in
  | start)
  |     cd $JBOSS_HOME/bin
  |     if [ -z "$SUBIT" ]; then
  |         eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
  |     else
  |         $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &" 
  |     fi
  |     ;;
  | stop)
  |     if [ -z "$SUBIT" ]; then
  |         $JBOSS_CMD_STOP
  |     else
  |         $SUBIT "$JBOSS_CMD_STOP"
  |     fi 
  |     ;;
  | restart)
  |     $0 stop
  |     $0 start
  |     ;;
  | *)
  |     echo "usage: $0 (start|stop|restart|help)"
  | esac
  | 

(2) Made script executable and changed ownership by doing the following:


  | sudo chown root:root /etc/init.d/jboss
  | sudo chmod ug+x /etc/init.d/jboss
  | 

(3) When I tried to start it, I received the following output (and JBoss didn't start):


  | JBOSS_CMD_START = cd /usr/jboss-5.1.0.GA/bin; /usr/jboss-5.1.0.GA/bin/run.sh -c default
  | 

Questions:

(1) What am I possibly doing wrong?

(2) How do I set it up so it runs as root user? Do I have to add a JBoss group and a JBoss user?

I can manually run JBoss through $JBOSS_HOME/bin but would love to have it running all the time...

Any help is greatly appreciated...

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4246311#4246311

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4246311



More information about the jboss-user mailing list