2 Replies Latest reply on Jan 29, 2014 6:13 PM by Stephen Correia

    JBOSS start/stop script

    Stephen Correia Newbie

      I developed my first shell script below to start/stop JBOSS based on currently running status.  It also checks on startup whether the log os over a certain size and makes a new one.  I'm sure there are some improvements that can be made - I'm interested in anyone's thoughts for improvement.




      #!/bin/bash

      #### Name:      jboss_control.sh

      #### Author:    Stephen F. Correia

      #### Date:      2014-01-28

      #### Version:   1.0

      #### Description:  Script to start/stop JBOSS based on current running status.

       

      #---Variables---#

      JBOSS_HOME="/apps/jboss-eap-6.2"

      JBOSS_LOG_FILE="${JBOSS_HOME}/logs/jboss_startup.log"

      SHORT_DATE=$(date +"%Y%m%d%H%M")

       

      #---Check to see if JBOSS is already running - ensure only one instance---#

      JBOSS_RUNNING=$(ps -ef | grep "Djboss.server.base.dir" | grep -v grep | wc -l)

       

      if [ $JBOSS_RUNNING -lt 1 ]; then

              #--Check log file size--#

              LOG_FILE_SIZE=$(stat -c %s $JBOSS_LOG_FILE)

              if [ $LOG_FILE_SIZE -ge 50000 ] ; then

                mv $JBOSS_LOG_FILE $JBOSS_LOG_FILE.$SHORT_DATE

              fi

       

              #---Start JBOSS---#

              nohup $JBOSS_HOME/bin/standalone.sh > $JBOSS_LOG_FILE 2> $JBOSS_LOG_FILE &

              if [ $? -ne 0 ]; then

                 echo "Error starting JBOSS - $?"

              else

                 echo "JBOSS started successfully"

              fi

      else

              #---Stop JBOSS---#

              echo "Stopping JBOSS..."

              $JBOSS_HOME/bin/jboss-cli.sh --connect ":shutdown"

      fi

       

      Thanks,

      Steve Correia

      tumtum73

        • 1. Re: JBOSS start/stop script
          Wolf-Dieter Fink Master

          The script look dangerous to me.

          You might stop a running instance by accident, I would use an explicit start/stop/restart parameter.

          Also you can not run several JBoss instances at the same host as the script is not able to divide and stop one existing instance or try to stop a non JBoss process if there is a process found with the jboss.server.base.dir.

           

          You might use the JBOSS_HOME to store a file with the PID if you start, with that file you can check the running instance.

          • 2. Re: JBOSS start/stop script
            Stephen Correia Newbie

            I probably should have clarified that this script will execute on a server dedicated to only running JBOSS and we only run a single instance of JBOSS - so this on/off toggle concept is not dangerous in my opinion.  That's not to say this is a good concept for all situations. 

             

            I like the suggestion to use parameters - I think I might introduce that to the script.

             

            Thanks allot for your feedback.

            Steve Correia

            tumtum73