RedHat Cluster custom Oracle “Agent”/script V1.0
Friday, April 24th, 2009Working with RH Cluster quite a lot, I have decided to create an online store of customer agents/scripts.
I have not, so far, invested the effort of making these agents accept settings from the cluster.conf file, but this might happen.
Let the library be!
Oracle DB script/agent:
Although I discovered (a bit late) that RH Cluster for Oracle Ent. Linux 5.2 does include oracle DB agent, this script should be good enough for RHEL4 RH Cluster versions as well.
This script only checks that the ‘smon’ process is up. Nothing fancy. This script can include, in the future, the ability to check that Oracle responses to SQL queries (meaning – actually working).
#!/bin/bash #Service script for Oracle DB under RH Cluster #Written by Ez-Aton #http://run.tournament.org.il # Global variables ORACLE_USER=oracle HOMEDIR=/home/$ORACLE_USER OVERRIDE_FILE=/var/tmp/oracle_override REC_LIST="[email protected]" function override () { if [ -f $OVERRIDE_FILE ] then exit 0 fi } function start () { su - $ORACLE_USER -c ". $HOMEDIR/.bash_profile ; sqlplus / as sysdba << EOF startup EOF " status } function stop () { su - $ORACLE_USER -c ". $HOMEDIR/.bash_profile ; sqlplus / as sysdba << EOF shutdown immediate EOF " status && return 1 || return 0 } function status () { ps -afu $ORACLE_USER | grep -v grep | grep smon return $? } function notify () { mail -s "$1 oracle on `hostname`" $REC_LIST < /dev/null } override case "$1" in start) start notify $1 ;; stop) stop # notify $1 ;; status) status ;; *) echo "Usage: $0 start|stop|status" ;; esac
I usually place this script (with execution permissions, of course) in /usr/local/sbin and call it as a “script” from the cluster configuration. You will probably be required to alter the first few variable lines to match to your environment.
Listener Agent/script:
The tnslsnr should be started/stopped as well, if we want the $ORACLE_HOME to migrate as well. This is its agent/script:
#!/bin/bash #Service script for Oracle DB under RH Cluster #Written by Ez-Aton #http://run.tournament.org.il ORACLE_USER=oracle HOMEDIR=/home/$ORACLE_USER OVERRIDE_FILE=/var/tmp/oracle_override function override () { if [ -f $OVERRIDE_FILE ] then exit 0 fi } function start () { su - $ORACLE_USER -c ". $HOMEDIR/.bash_profile ; lsnrctl start" status } function stop () { su - $ORACLE_USER -c ". $HOMEDIR/.bash_profile ; lsnrctl stop" status && return 1 || return 0 } function status () { su - $ORACLE_USER -c ". $HOMEDIR/.bash_profile ; lsnrctl status" } override case "$1" in start) start ;; stop) stop ;; status) status ;; *) echo "Usage: $0 start|stop|status" ;; esac
Again – place it in /usr/local/sbin and call it from the cluster configuration file as type “script”.
I will add more agents and more resources for RedHat Cluster in the future.