2 Replies Latest reply on Jul 3, 2003 5:12 AM by mallim

    Setting up JBoss as a Linux Service

    duncangroenewald

      Can anyone provide the necessary scripts for running JBoss as a service under Linux (Red Hat v9). Sorry am not a Linux expert (yet!) and its not quite the same as setting up a service under NT.

      I have tried the following script file to set up an RmiJdbc server (just to keep things simple to start with) - but the daemon function never seems to return - it blocks. Is there some way of getting the VM to start and provide a return code ?

      I was hoping this would work and I could use the same approach to start JBoss !! Its never that simple is it !!

      #!/bin/bash
      #
      # /etc/rc.d/init.d/rmijdbc
      #
      # Starts the rmijdbc server
      #
      # chkconfig: 345 95 5
      # description: database server
      # processname: rmijdbc

      # Source function library.
      . /etc/init.d/functions

      #test -x /usr/sbin/rmijdbc || exit 0

      RETVAL=0

      RJ_HOME=/home/duncan/apps/bin
      #JAVA_HOME=/usr/java/j2sdk1.4.2
      PB_HOME=/home/duncan/apps/pointbase
      PATH=$PATH:$JAVA_HOME/bin
      RJ_CLASSPATH=/home/duncan/data/java:$PB_HOME/lib/pbembedded45GA217.jar:$CLASSPATH

      OPTS="-server -classpath $RJ_CLASSPATH -Djava.rmi.server.hostname=dunxpc org.objectweb.rmijdbc.RJJdbcServer -port 9091 com.pointbase.jdbc.jdbcUniversalDriver"


      #
      # See how we were called.
      #

      prog="rmijdbc"

      start() {
      # Check if rmijdbc is already running
      if [ ! -f /var/lock/subsys/rmijdbc ]; then
      echo -n $"Starting $prog: "
      daemon $JAVA_HOME/bin/rmijdbc $OPTS
      RETVAL=$?
      [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rmijdbc
      echo
      fi
      return $RETVAL
      }

      stop() {
      echo -n $"Stopping $prog: "
      killproc $JAVA_HOME/bin/rmijdbc
      RETVAL=$?
      [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/rmijdbc
      echo
      return $RETVAL
      }


      restart() {
      stop
      start
      }

      reload() {
      restart
      }

      status_at() {
      status /usr/sbin/atd
      }

      case "$1" in
      start)
      start
      ;;
      stop)
      stop
      ;;
      reload|restart)
      restart
      ;;
      condrestart)
      if [ -f /var/lock/subsys/atd ]; then
      restart
      fi
      ;;
      status)
      status_at
      ;;
      *)
      echo $"Usage: $0 {start|stop|restart|condrestart|status}"
      exit 1
      esac

      exit $?
      exit $RETVAL

        • 1. Re: Setting up JBoss as a Linux Service
          jonlee

          This is a pretty simple init.d script. You can tidy it up a bit, I guess. Call the script /etc/init.d/jboss and use chkconfig to install it so the service starts and stops in the right startup and shutdown sequence when booting and shutting down the OS. "man chkconfig" for more details. I execute run.sh as a background process and look for the JBoss process found with "IBMJava2" - the test could be better constructed and is no guarantee for operation, but it takes a couple of minutes to start JBoss so I don't particularly want to hold up the OS boot process. I'm sure you can polish it up.

          #!/bin/sh
          #
          # chkconfig: - 91 35
          # description: Starts and stops the JBoss service.
          #
          # pidfile: null


          # Source function library.
          if [ -f /etc/init.d/functions ] ; then
          . /etc/init.d/functions
          elif [ -f /etc/rc.d/init.d/functions ] ; then
          . /etc/rc.d/init.d/functions
          else
          exit 0
          fi

          # Avoid using root's TMPDIR
          unset TMPDIR

          # Source networking configuration.
          . /etc/sysconfig/network

          # Check that networking is up.
          [ ${NETWORKING} = "no" ] && exit 0

          RETVAL=0


          start() {
          if [ -f /var/lock/subsys/jboss ] ; then
          return $RETVAL
          fi
          KIND="JBoss"
          echo -n $"Starting $KIND services: "
          cd /usr/local/JBoss-3.2.0/bin
          su -p -s /bin/sh -c "./run.sh 2>&1 > run.log &" apache
          sleep 3
          RETVAL=`ps ax | grep 'IBMJava2' | grep -c -v grep`
          if [ $RETVAL -eq 1 ] ; then
          touch /var/lock/subsys/jboss
          echo_success
          else
          echo_failure
          fi
          echo ""
          return $RETVAL
          }

          stop() {
          KIND="JBoss"
          echo -n $"Shutting down $KIND services: "
          cd /usr/local/JBoss-3.2.0/bin
          su -p -s /bin/sh -c "./shutdown.sh --" apache
          RETVAL=$?
          if [ $RETVAL -eq 1 ] ; then
          rm -f /var/lock/subsys/jboss
          echo_success
          else
          echo_failure
          fi
          echo ""
          return $RETVAL
          }

          restart() {
          stop
          start
          }

          case "$1" in
          start)
          start
          ;;
          stop)
          stop
          ;;
          restart)
          restart
          ;;
          *)
          echo $"Usage: $0 {start|stop|restart}"
          exit 1
          esac

          exit $?

          • 2. Re: Setting up JBoss as a Linux Service
            mallim

            Hi

            You can consider using Wrapper (http://wrapper.sourceforge.net) which is applicable for other platforms also.