Monday, 13 August 2012

starting nodeManager and startWebLogic automatically

There is a lot of stuff on the new, but not a lot of good stuff on this topic.  My server is in production mode, so you cannot just pass is usernames and passwords to the start web logic script.  Perhaps you can use a here file, but that might be for next time.  I tried a basic here file and did not get too much success.  I read the script startWebLogic.sh and thought that the only option was to set the WLS_PW and WLS_USER values for the shell that starts the command.  The problem with this method is that when you do “ps –ef |grep weblogic”, you get a bit of a surprise!

I’ve done a couple of things to get this working.  Firstly I’ve edited the nodemanager.properties file to start things automatically if there is a crash.  Not too sure if this is going to help if the adminServer is already down?  I thought it was going to be the fix that I was waiting for…  Not too sure that it was.

edit the file below

./wlserver_10.3/common/nodemanager/nodemanager.properties

change the lines to be true

CrashRecoveryEnabled=true
StartScriptEnabled=true

I did a restart of the node manager and the admin server did not come up – Doh.

So, I then created the following script called weblogic and whacked it into the /etc/init.d spot: 

remember to chmod 700, as I have some secret squirrel passwords in it. 

It’s a bit fancy, and I attribute the fanciness to BP who works with me.  You know who you are, thanks!

 

#!/bin/sh
#
# /etc/rc.d/init.d/weblogic
#
# A start/stop script for weblogic on Oracle Unbreakable Linux x86_64
#
# chkconfig: 2 99 1
# description: Starts and stops weblogic
#

# Settings and initialisation.
SERVICE="weblogic"
DESCRIPTION="weblogic and notemanager"
SETCOLOR_TITLE="echo -en \\033[0;36m"
RETVAL=0

# Service defaults
WLSUSER="oracle"
RUNWLS="/bin/su ${WLSUSER} -lc"
WLSPROJ="/u01/app/oracle/Middleware/user_projects/domains/my_domain"
WLSSVR="/u01/app/oracle/Middleware/wlserver_10.3/server"
WLS_USER=weblogic
WLS_PW=**Your weblogic user password”


# 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 1
fi

# Avoid using root's TMPDIR
unset TMPDIR

start() {
        echo -n $"Starting ${DESCRIPTION} services: "
        echo
        RETVAL=0

        echo ; $SETCOLOR_TITLE ; echo "weblogic:" ; $SETCOLOR_NORMAL
        ${RUNWLS} "export WLS_USER=$WLS_USER;export WLS_PW=$WLS_PW; ${WLSPROJ}/bin/startWebLogic.sh &2>1 &"
        RETVAL_WLS=$?
#        sleep 60

        echo ; $SETCOLOR_TITLE ; echo "weblogic node manager:" ; $SETCOLOR_NORMAL
        ${RUNWLS} "${WLSSVR}/bin/startNodeManager.sh &2>1 &"
        RETVAL_WLSNM=$?
#        sleep 60

        RETVAL=`expr $RETVAL_WLS + $RETVAL_WLSNM`
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/${SERVICE} || RETVAL=1

        return $RETVAL
}

stop() {
        echo -n $"Shutting down ${DESCRIPTION} services: "
        echo
        RETVAL=0

        echo ; $SETCOLOR_TITLE ; echo "weblogic:" ; $SETCOLOR_NORMAL
        ${RUNWLS} "${WLSPROJ}/bin/stopWebLogic.sh $WLS_USER $WLS_PW &"
        RETVAL_WLS=$?

        kill -9 `ps -ef |grep -i "jdk Weblogic.nodemanager" |grep -v grep | awk '{print $2}'`

        RETVAL=`expr $RETVAL_WLS`

        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${SERVICE}
        return $RETVAL
}


status() {

                echo ; $SETCOLOR_TITLE ; echo "${DESCRIPTION} weblogic Status:" ; $SETCOLOR_NORMAL
                ps -ef|grep startWebLogic.sh|grep -vE 'grep|ps -ef|-sh|awk|sort|uniq|ksh|su'|awk '{print $2, $9, $10, $11, $12, $13}'
                echo ; $SETCOLOR_TITLE ; echo "${DESCRIPTION} weblogic node manager Status:" ; $SETCOLOR_NORMAL
                ps -ef|grep startNodeManager.sh|grep -vE 'grep|ps -ef|-sh|awk|sort|uniq|ksh|su'|awk '{print $2,$9}'
}

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

exit $?

 

Despite being a little verbose, the above script is working!

[root@vsydwls01 init.d]# chkconfig weblogic --add
[root@vsydwls01 init.d]# chkconfig  --level 5 weblogic on
[root@vsydwls01 init.d]# chkconfig  --level 3 weblogic on
[root@vsydwls01 init.d]# chkconfig weblogic --list
weblogic        0:off   1:off   2:on    3:on    4:off   5:on    6:off

 

What do those level numbers mean: (thanks Wikipedia).  3 & 5 are very common choices.

Code Information
0 Halt
1 Single-User mode
2 Multi-user mode console logins only (without networking)
3 Multi-User mode, console logins only
4 Not used/User-definable
5 Multi-User mode, with display manager as well as console logins (X11)
6 Reboot

No comments:

Extending JDE to generative AI