Tuesday, July 30, 2013

Weblogic Admin server startup service script

1) create a file in this path   /opt/init.d/wlsdomains

2)copy the below script
#!/bin/bash
#
# Weblogic Admin Server Startup Script
#
# chkconfig: 345 94 06
# description: Weblogic
# processname: Java

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

WLS_HOME=/opt/apps/wls/Oracle/Middleware/
WLS_USER=wlsadmin
DOMAIN_HOME=/opt/apps/wls/domains
DOMAIN=test
#set the return value of the script to 0, which means no error.
RETVAL=0

prog="WebLogic Admin Server"
PIDFILE=$DOMAIN_HOME/$DOMAIN/wls_pid

function pidfile()
{
    PID=`cat $PIDFILE`
    echo "PID=$PID"
}

start() {
echo -n $"Starting $prog: "
nohup su - $WLS_USER -c $DOMAIN_HOME/$DOMAIN/startWebLogic.sh  > /tmp/$DOMAIN.log &
echo $! > $PIDFILE
echo "Starting $prog: $DOMAIN.... OK"
}

stop() {
echo -n $"Stopping $prog: "
nohup su - $WLS_USER -c $DOMAIN_HOME/$DOMAIN/bin/stopWebLogic.sh > /tmp/$DOMAIN.log &
echo "Shutting down $prog: $DOMAIN... OK"
rm -rf $PIDFILE
}

restart() {
  stop
  sleep 10
  start
}

reload() {
        restart
}

case "$1" in
start)
        start
pidfile
        ;;
stop)
pidfile
stop
        ;;
reload)
        reload
        ;;
restart)
        restart
        ;;
status)
#STATUS=`ps -ef | grep java | grep weblogic | wc -l`
PID=`cat $PIDFILE`
if `ps -p $PID > /dev/null`; then
             echo "$prog: $DOMAIN is running, PID=$PID ok."
        else
             echo "$prog: $DOMAIN is not running ..."
        fi
;;
*)

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

exit 1

3) chang the file permission
  #chmod  +x /etc/init.d/wlsdomains

4) add in to service 
  #cd /etc/init.d
  #chconfig --add wlsdomains
  #chkconfig wlsdomains on
  #service wlsdomains start

No comments:

Post a Comment