services.sh script :
# Check services for databases
#---------------------------------------------------------------------
#!/bin/bash
#checks if services are running on preferred nodes
for i in `crsctl stat res -t | grep svc | grep -v world`; do
lvService=`echo $i | awk 'BEGIN { FS = ".svc" } ; { print $1 }' | cut -f3,4 -d'.'`
lvDatabase=`echo $i | cut -f2 -d'.'`
lvServiceEnabled=`srvctl config service -s $lvService -d $lvDatabase | grep "is enabled"`
lvServicePreferred=`srvctl config service -s $lvService -d $lvDatabase | grep "Preferred instances:" | cut -f3 -d' ' | sed 's/,/\n/g'|sort`
lvServiceAvailable=`srvctl config service -s $lvService -d $lvDatabase | grep "Available instances:" | cut -f3 -d' ' | sed 's/,/\n/g'|sort`
lvInstanceRunning=`srvctl status service -s $lvService -d $lvDatabase | grep "is running" | cut -f7 -d' ' | sed 's/,/\n/g'|sort`
if [ "$lvServiceEnabled" = "" ]; then
echo "INFORMATION.Service ${lvService} is disabled and not running in prefered ${lvServicePreferred}"
elif [ "$lvInstanceRunning" = "" ]; then
echo "================================================================================================================="
echo "FAIL.Service ${lvService} is enabled but not running on prefered ${lvServicePreferred}"
echo "-----------------------------------------------------------------------------------------------------------------"
echo "Command to run"
echo "srvctl start service -d ${lvDatabase} -s ${lvService}"
echo "-----------------------------------------------------------------------------------------------------------------"
elif [ "$lvServicePreferred" = "$lvInstanceRunning" ]; then
echo "SUCCESS.Service ${lvService} is running in preferred location(s) ${lvServicePreferred}"
else
echo "==============================================================================================================="
echo "WARNING.Service ${lvService} is running in location(s) ${lvInstanceRunning}. Should be in ${lvServicePreferred}"
echo "Test of services failed for database ${lvDatabase}"
echo "---------------------------------------------------------------------------------------------------------------"
echo "Command to run"
echo "srvctl relocate service -d ${lvDatabase} -s ${lvService} -i ${lvInstanceRunning} -t ${lvServicePreferred}"
echo "---------------------------------------------------------------------------------------------------------------"
fi
done
# Check services for databases
#---------------------------------------------------------------------
#!/bin/bash
#checks if services are running on preferred nodes
for i in `crsctl stat res -t | grep svc | grep -v world`; do
lvService=`echo $i | awk 'BEGIN { FS = ".svc" } ; { print $1 }' | cut -f3,4 -d'.'`
lvDatabase=`echo $i | cut -f2 -d'.'`
lvServiceEnabled=`srvctl config service -s $lvService -d $lvDatabase | grep "is enabled"`
lvServicePreferred=`srvctl config service -s $lvService -d $lvDatabase | grep "Preferred instances:" | cut -f3 -d' ' | sed 's/,/\n/g'|sort`
lvServiceAvailable=`srvctl config service -s $lvService -d $lvDatabase | grep "Available instances:" | cut -f3 -d' ' | sed 's/,/\n/g'|sort`
lvInstanceRunning=`srvctl status service -s $lvService -d $lvDatabase | grep "is running" | cut -f7 -d' ' | sed 's/,/\n/g'|sort`
if [ "$lvServiceEnabled" = "" ]; then
echo "INFORMATION.Service ${lvService} is disabled and not running in prefered ${lvServicePreferred}"
elif [ "$lvInstanceRunning" = "" ]; then
echo "================================================================================================================="
echo "FAIL.Service ${lvService} is enabled but not running on prefered ${lvServicePreferred}"
echo "-----------------------------------------------------------------------------------------------------------------"
echo "Command to run"
echo "srvctl start service -d ${lvDatabase} -s ${lvService}"
echo "-----------------------------------------------------------------------------------------------------------------"
elif [ "$lvServicePreferred" = "$lvInstanceRunning" ]; then
echo "SUCCESS.Service ${lvService} is running in preferred location(s) ${lvServicePreferred}"
else
echo "==============================================================================================================="
echo "WARNING.Service ${lvService} is running in location(s) ${lvInstanceRunning}. Should be in ${lvServicePreferred}"
echo "Test of services failed for database ${lvDatabase}"
echo "---------------------------------------------------------------------------------------------------------------"
echo "Command to run"
echo "srvctl relocate service -d ${lvDatabase} -s ${lvService} -i ${lvInstanceRunning} -t ${lvServicePreferred}"
echo "---------------------------------------------------------------------------------------------------------------"
fi
done