English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Writing a script to monitor and start/stop weblogic services using linux bash script

Sometimes, Linux systems need to perform HA or similar functions and need to configure Weblogic scripts to start, stop, and check status, which can be written as follows

Command format: Weblogic server start|stop|restart|status

### BEGIN WLS Configuration
DOMAIN_NAME=base_domain
SERVER_NAME=AServer 
ADMIN_URL="t3://ip:7001"
DOMAIN_PATH=/Oracle/Middleware/user_projects/domains/${DOMAIN_NAME}
#Use this command to get the process ID of the Weblogic corresponding service process
WLS_PID=`ps -ef|grep java|grep =${SERVER_NAME}|awk '{print $2'`
#USER_NAME=`logname`
USER_NAME=`whoami`
## WLS_MEMORY
USER_MEM_ARGS="-Xms2048m -Xmx3096m -XX:PermSize=256m -XX:MaxPermSize=512m""
export USER_MEM_ARGS
### END WLS Configuration
######### Weblogic server start|stop|restart|status
#Used to wait for the start and stop of the process
wait_for_pid () 
{
  try=0
    case "$1" in
      (
        while test $try -lt 7 ; do
        printf .
        try=`expr $try + 1`
        sleep 1
        done            
        WLS_PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2'`            
        if [ "$WLS_PID" != "" ] ; then
          try=''                         
        fi
      ;;
      (
        while test $try -lt 35 ; do  
        WLS_PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2'`
        if [ "${WLS_PID}" = "" ] ; then
          try=''
        break
        fi
        printf .
        try=`expr $try + 1`
        sleep 1
        done
      ;;
    esac
}
#Determine the operation username, cannot be root, need to use weblogic user
if [ "$USER_NAME" = "root" ] ; then
  echo "USER_NAME is $USER_NAME! Please use weblogic!"
  exit 1
fi
#domain cannot be empty
if [ "$DOMAIN_NAME" = "" ] ; then
  echo "DOMAIN_NAME is not set! Please set DOMAIN_NAME!"
  exit 1
fi
#service cannot be empty
if [ "$SERVER_NAME" = "" ] ; then
  echo "SERVER_NAME is not set! Please set SERVER_NAME!"
  exit 1
fi
#url cannot be empty
if [ "$ADMIN_URL" = "" ] ; then
  echo "ADMIN_URL is not set! Using default ADMIN_URL!"
fi
#If it is a command to view the status       
if [ "$1" = "status" ]
  then        
  if [ "${WLS_PID}" = "" ] ; then
   echo "No pid - "$SERVER_NAME is not running !"
    exit 1
 else 
  echo "$SERVER_NAME is running !"
  exit 0
 fi
fi
printf "Terminating $SERVER_NAME "
  if [ "${WLS_PID}" = "" ] ; then
    echo "No pid - "$SERVER_NAME is not running !"
  else          
    kill -9 $WLS_PID
  wait_for_pid removed 
  if [ -n "$try" ] ; then
  echo " failed "
  exit 1         
  fi
    echo " done ! "
    exit 0
 fi
#If it is a stop command, this is not used here        
if [ "$1" = "stop" ]
then        
echo ""
else
#Start command
printf "Starting $SERVER_NAME "
  if echo $SERVER_NAME|grep -q dmin ; then        
    nohup sh $DOMAIN_PATH/bin/startWebLogic.sh &
  else        
    nohup sh $DOMAIN_PATH/bin/startManagedWebLogic.sh $SERVER_NAME $ADMIN_URL &
  fi        
  wait_for_pid created 
  if [ -n "$try" ] ; then
    echo " failed "
    exit 1
  else
    echo " done ! "
    exit 0
  fi   
fi 
echo "To check the log, you may execute:"
echo "tail -100f "

The above is the script writing method of the Linux bash script for monitoring the start and stop of the weblogic service introduced by the editor, I hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time!

Statement: The content of this article is from the Internet, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report, and provide relevant evidence. Once verified, this site will immediately delete the suspected infringing content.)

You may also like