Wednesday, August 19, 2015

Getting State of all Servers in a domain

First you may create secure key files to avoid using plain text uname and password for weblogic.

Step1:

Run WLST --> /opt/admin/fmw/oracle_common/common/bin/wlst.sh

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline>connect('weblogic','welcome1',url='t3://localhost:7001')
wls:/myDomain/serverConfig> storeUserConfig('/tmp/myUserConfigFile','/tmp/myUserKeyFile')
wls:/myDomain/serverConfig> exit()

Step2:

File name: getAllServerStatus.py

import sys
import os

connect(userConfigFile='myUserConfigFile', userKeyFile='myUserKeyFile', url='t3://localhost:7001')
domainRuntime()
cd('ServerRuntimes')

sServers=domainRuntimeService.getServerRuntimes()
for sServer in sServers:
     serverName=sServer.getName();
     print '###' , serverName,'State is:', sServer.getState()

disconnect()
exit()

Step3:

FileName: getAllServerState_wls.sh

#!/bin/ksh

echo "Getting All Servers State......"

/opt/admin/fmw/oracle_common/common/bin/wlst.sh getAllServerStatus.py > /tmp/allServerStatus.log

cat /tmp/allServerStatus.log | grep -i state

exit 0

Example Run:

./getAllServerState_wls.sh

Getting All Servers State......
### AdminServer State is: RUNNING
### my_server1 State is: RUNNING
### my_server2 State is: RUNNING

Tuesday, August 18, 2015

Get Server Status in Weblogic using WLST

First you may create secure key files to avoid using plain text uname and password for weblogic.

Step1:

Run WLST --> /opt/admin/fmw/oracle_common/common/bin/wlst.sh

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline>connect('weblogic','welcome1',url='t3://localhost:7001')
wls:/myDomain/serverConfig> storeUserConfig('/tmp/myUserConfigFile','/tmp/myUserKeyFile')
wls:/myDomain/serverConfig> exit()

Step2:

File name: getServerStatus.py

import sys
import os

sServer=sys.argv[1]

connect(userConfigFile='myUserConfigFile', userKeyFile='myUserKeyFile', url='t3://localhost:7001')
state(sServer)

disconnect()

exit()

Step3:

FileName: getServerState_wls.sh

#!/bin/ksh

usage()
{
 echo "\n!!!!!Usage!!!!!!!"
 echo
 echo "   getServerState_wls.sh "
 echo "\n getServerState_wls.sh myserver1"
 echo
}

if [ $# -ne 1 ]
then
 usage
 exit 2
fi

SERVER=$1

echo "Server= ${SERVER}"
echo

/opt/admin/fmw/oracle_common/common/bin/wlst.sh getServerStatus.py ${SERVER} > /tmp/serverstatus.log
state=`cat /tmp/serverstatus.log | grep -i state`
echo $state


exit 0

Example Run:

 ./getServerState_wls_adp.sh MY_server2
Server= MY_server2


Current state of 'MY_server2' : RUNNING

Wednesday, August 12, 2015

Managed Server Operations without NM

wls_ms_operations.sh

Usage: ./wls_ms_operations.sh {start|stop|restart} {SERVER-NAME}

#!/bin/bash
server_name=$2
export DOMAIN_LOG=/opt/admin/fmw/

stop() {
        echo "Stopping Managed Server(s)..." $server_name
        echo $SUDO_USER "gave stop command for $server_name at" `/bin/date` > $DOMAIN_LOG/shutdown_$server_name.log
        nohup /opt/admin/fmw/domains/myDomain/bin/stopManagedWebLogic.sh $server_name > $DOMAIN_LOG/shutdown_$server_name.log 2> /dev/null &
        echo "Follow the log @ /opt/admin/fmw/domains/myDomain/servers/${server_name}/logs/"

}

start() {

        echo "Starting Managed Server..." $server_name
        echo $SUDO_USER "gave start command for $server_name at" `/bin/date` > $DOMAIN_LOG/startup_$server_name.log
        nohup /opt/admin/fmw/domains/myDomain/bin/startManagedWebLogic.sh $server_name t3://localhost:7001 2> /dev/null &
        echo "Follow the log @ /opt/admin/fmw/domains/myDomain/servers/${server_name}/logs/"

        exit 1
}

restart() {
        echo "Stopping Managed Server(s)..." $server_name
        echo $SUDO_USER "gave stop command for $server_name at" `/bin/date` > $DOMAIN_LOG/shutdown_$server_name.log
        nohup /opt/admin/fmw/domains/myDomain/bin/stopManagedWebLogic.sh $server_name > $DOMAIN_LOG/shutdown_$server_name.log 2> /dev/null &
        echo "Follow the log @ /opt/admin/fmw/domains/myDomain/servers/${server_name}/logs/"
sleep 10
pid=$(ps auxwww | grep ${server_name}| grep Dweblogic | cut -c 10-15 | tr -d ' ')
if [[ ! -z "$pid" ]]
                then
                        `kill -9 ${pid}`
echo "Killed the process..."
fi
        
echo "Now Starting Managed Server..." $server_name
        echo $SUDO_USER "gave start command for $server_name at" `/bin/date` > $DOMAIN_LOG/startup_$server_name.log
        nohup /opt/admin/fmw/domains/myDomain/bin/startManagedWebLogic.sh $server_name t3://localhost:7001 2> /dev/null &
        echo "Follow the log @ /opt/admin/fmw/domains/myDomain/servers/${server_name}/logs/"
        exit 1

}

case "$1" in

        "start")
                start
                ;;
        "stop")
                stop
                ;;
       "restart")
                restart
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart} {SERVER-NAME}"
                exit 1
                ;;

esac
exit

Tuesday, August 11, 2015

Admin Server Operations

wls_admin_operations.sh

#!/bin/bash

export SERVER_LOG=/opt/admin/fmw/

start() {
        echo "Starting WebLogic Server(s)..."

echo $SUDO_USER "gave start command for Admin Server at" `/bin/date` > $SERVER_LOG/startup.log

nohup /opt/admin/fmw/domains/myDomain/bin/startWebLogic.sh > $SERVER_LOG/startup.log 2>&1

}

stop() {
        echo "Stopping WebLogic Server(s)..."
echo $SUDO_USER "gave stop command for Admin Server at" `/bin/date` > $SERVER_LOG/shutdown.log
nohup /opt/admin/fmw/domains/myDomain/bin/stopWebLogic.sh > $SERVER_LOG/shutdown.log 2>&1

}

restart() {
        echo "Stopping WebLogic Server(s)..."
        echo $SUDO_USER "gave stop command for Admin Server at" `/bin/date` > $SERVER_LOG/shutdown.log
        nohup /opt/admin/fmw/domains/myDomain/bin/stopWebLogic.sh > $SERVER_LOG/shutdown.log 2>&1
        sleep 40
        echo "Starting WebLogic Server(s)..."
        echo $SUDO_USER "gave start command for Admin Server at" `/bin/date` > $SERVER_LOG/startup.log
        nohup /opt/admin/fmw/domains/myDomain/bin/startWebLogic.sh > $SERVER_LOG/startup.log 2>&1
}

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