4 Replies Latest reply on Mar 2, 2012 10:10 AM by djabba74

    How to start JBoss AS 7 as a service on CentOS 6

    fernandoacorreia

      I searched the web and the JBoss documentation but I couldn't find authoritative information on how to setup JBoss AS 7 on CentOS 6 so that it runs automatically as a service.

       

      The best match I could find was about JBoss 6: http://davidghedini.blogspot.com/2011/03/install-jboss-6-on-centos.html

       

      Could anyone point me in the right direction?

        • 1. Re: How to start JBoss AS 7 as a service on CentOS 6
          nickarls

          Make a symlink from /etc/init.d/jboss -> JBOSS/bin/init.d/jboss-as-standalone.sh and do chkconfig --add jboss

          • 2. Re: How to start JBoss AS 7 as a service on CentOS 6
            fernandoacorreia

            Nicklas, thank you for your answer.

             

            I downloaded both jboss-as-web-7.0.2.Final.tar.gz and jboss-as-7.0.2.Final.tar.gz and neither of them seems to include a bin/init.d/jboss-as-standalone.sh file. They have bin/standalone.sh but that doesn't look like a init.d script.

             

            Edit: I found that file in 7.1 Beta, so I'll try the script with 7.0.2.

            • 3. Re: How to start JBoss AS 7 as a service on CentOS 6
              fernandoacorreia

              For the record, I solved the issue by adapting the script in 7.1 Beta. I still think there should be more guidance on how to properly install JBoss AS 7 on CentOS.

               

              #!/bin/sh

              #

              # JBoss standalone control script

              #

              # chkconfig: - 80 20

              # description: JBoss AS Standalone

              # processname: standalone

              # pidfile: /var/run/jboss-as/jboss-as-standalone.pid

              # config: /etc/jboss-as/jboss-as.conf

               

              # Source function library.

              . /etc/init.d/functions

               

              # Load Java configuration.

              [ -r /etc/java/java.conf ] && . /etc/java/java.conf

              export JAVA_HOME

               

              # Load JBoss AS init.d configuration.

              if [ -z "$JBOSS_CONF" ]; then

                JBOSS_CONF="/etc/jboss-as/jboss-as.conf"

              fi

               

              [ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"

               

              # Set defaults.

               

              if [ -z "$JBOSS_HOME" ]; then

                JBOSS_HOME=/usr/share/jboss-as

              fi

              export JBOSS_HOME

               

              if [ -z "$JBOSS_PIDFILE" ]; then

                JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-standalone.pid

              fi

              export JBOSS_PIDFILE

               

              if [ -z "$JBOSS_CONSOLE_LOG" ]; then

                JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log

              fi

               

              if [ -z "$JBOSS_USER" ]; then

                JBOSS_USER=jboss

              fi

               

              if [ -z "$STARTUP_WAIT" ]; then

                STARTUP_WAIT=30

              fi

               

              if [ -z "$SHUTDOWN_WAIT" ]; then

                SHUTDOWN_WAIT=30

              fi

               

              if [ -z "$JBOSS_CONFIG" ]; then

                JBOSS_CONFIG=standalone.xml

              fi

               

              JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh

               

              prog='jboss-as'

               

              CMD_PREFIX=''

               

              if [ ! -z "$JBOSS_USER" ]; then

                if [ -x /etc/rc.d/init.d/functions ]; then

                  CMD_PREFIX="daemon --user $JBOSS_USER"

                else

                  CMD_PREFIX="su - $JBOSS_USER -c"

                fi

              fi

               

              start() {

                echo -n "Starting $prog: "

                if [ -f $JBOSS_PIDFILE ]; then

                  read ppid < $JBOSS_PIDFILE

                  if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then

                    echo -n "$prog is already running"

                    failure

                    echo

                    return 1

                  else

                    rm -f $JBOSS_PIDFILE

                  fi

                fi

                mkdir -p $(dirname $JBOSS_CONSOLE_LOG)

                cat /dev/null > $JBOSS_CONSOLE_LOG

               

                mkdir -p $(dirname $JBOSS_PIDFILE)

                chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true

                #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &

                #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &

               

                if [ ! -z "$JBOSS_USER" ]; then

                  if [ -x /etc/rc.d/init.d/functions ]; then

                    daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT --server-config=$JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &

                  else

                    su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT --server-config=$JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &

                  fi

                fi

               

                count=0

                launched=false

               

                until [ $count -gt $STARTUP_WAIT ]

                do

                  grep 'JBoss AS.*started in' $JBOSS_CONSOLE_LOG > /dev/null

                  if [ $? -eq 0 ] ; then

                    launched=true

                    break

                  fi

                  sleep 1

                  let count=$count+1;

                done

               

                success

                echo

                return 0

              }

               

              stop() {

                echo -n $"Stopping $prog: "

                count=0;

               

                if [ -f $JBOSS_PIDFILE ]; then

                  read kpid < $JBOSS_PIDFILE

                  let kwait=$SHUTDOWN_WAIT

               

                  # Try issuing SIGTERM

               

                  kill -15 $kpid

                  until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]

                  do

                    sleep 1

                    let count=$count+1;

                  done

               

                  if [ $count -gt $kwait ]; then

                    kill -9 $kpid

                  fi

                fi

                rm -f $JBOSS_PIDFILE

                success

                echo

              }

               

              status() {

                if [ -f $JBOSS_PIDFILE ]; then

                  read ppid < $JBOSS_PIDFILE

                  if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then

                    echo "$prog is running (pid $ppid)"

                    return 0

                  fi

                fi

                echo "$prog is not running"

              }

               

              case "$1" in

                start)

                    start

                    ;;

                stop)

                    stop

                    ;;

                restart)

                    $0 stop

                    $0 start

                    ;;

                status)

                    status

                    ;;

                *)

                    ## If no parameters are given, print which are avaiable.

                    echo "Usage: $0 {start|stop|status|restart|reload}"

                    exit 1

                    ;;

              esac

              • 4. Re: How to start JBoss AS 7 as a service on CentOS 6
                djabba74

                On CentOS 6 (and maybe other Distros too), the /etc/rc.d/init.d/functions has no executable flag set. The jboss init.d script itself sources it with  ". /etc/rc.d/init.d/functions"

                 

                ll /etc/rc.d/init.d/functions

                -rw-r--r--. 1 root root 18171 Oct  7 16:01 /etc/rc.d/init.d/function

                 

                So you might want to fix the jboss init.d script the following way:

                 

                # diff  /opt/jboss-as/bin/init.d/jboss-as-standalone.sh /etc/init.d/jboss

                89c89

                <     if [ -x /etc/rc.d/init.d/functions ]; then

                ---

                >     if [ -r /etc/rc.d/init.d/functions ]; then