diff --git a/heartbeat/oralsnr b/heartbeat/oralsnr index 1e4fe8d60..bc85abe01 100755 --- a/heartbeat/oralsnr +++ b/heartbeat/oralsnr @@ -1,429 +1,429 @@ #!/bin/sh # # # oralsnr # # Description: Manages an Oracle Listener as a High-Availability # resource # # # Author: Dejan Muhamedagic # Support: linux-ha@lists.linux-ha.org # License: GNU General Public License (GPL) # Copyright: (C) 2006 International Business Machines, Inc. # # This code inspired by the DB2 resource script # written by Alan Robertson # # An example usage in /etc/ha.d/haresources: # node1 10.0.0.170 oralsnr::sid::home::user::listener # # See usage() function below for more details... # # OCF instance parameters: # OCF_RESKEY_sid (mandatory; for the monitor op) # OCF_RESKEY_home (optional; else read it from /etc/oratab) # OCF_RESKEY_user (optional; user to run the listener) # OCF_RESKEY_listener (optional; defaults to LISTENER) # # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### SH=/bin/sh usage() { methods=`oralsnr_methods` methods=`echo $methods | tr ' ' '|'` cat <<-! usage: $0 ($methods) $0 manages an Oracle Database instance as an HA resource. The 'start' operation starts the database. The 'stop' operation stops the database. The 'status' operation reports whether the database is running The 'monitor' operation reports whether the database seems to be working The 'validate-all' operation reports whether the parameters are valid The 'methods' operation reports on the methods $0 supports ! } meta_data() { cat < 1.0 Resource script for Oracle Listener. It manages an Oracle Listener instance as an HA resource. Manages an Oracle TNS listener The Oracle SID (aka ORACLE_SID). Necessary for the monitor op, i.e. to do tnsping SID. sid The Oracle home directory (aka ORACLE_HOME). If not specified, then the SID should be listed in /etc/oratab. home Run the listener as this user. user Listener instance to be started (as defined in listener.ora). Defaults to LISTENER. listener END } # # methods: What methods/operations do we support? # oralsnr_methods() { cat <<-! start stop status monitor validate-all methods meta-data usage ! } # Gather up information about our oralsnr instance ora_info() { ORACLE_SID=$1 ORACLE_HOME=$2 ORACLE_OWNER=$3 # get ORACLE_HOME from /etc/oratab if not set [ x = "x$ORACLE_HOME" ] && ORACLE_HOME=`awk -F: "/^$ORACLE_SID:/"'{print $2}' /etc/oratab` # there a better way to find out ORACLE_OWNER? [ x = "x$ORACLE_OWNER" ] && ORACLE_OWNER=`ls -ld $ORACLE_HOME/. 2>/dev/null | awk 'NR==1{print $3}'` sqlplus=$ORACLE_HOME/bin/sqlplus lsnrctl=$ORACLE_HOME/bin/lsnrctl tnsping=$ORACLE_HOME/bin/tnsping } testoraenv() { # Let's make sure a few important things are set... if [ x = "x$ORACLE_HOME" ]; then ocf_log info "ORACLE_HOME not set" return $OCF_ERR_CONFIGURED fi if [ x = "x$ORACLE_OWNER" ]; then ocf_log info "ORACLE_OWNER not set" return $OCF_ERR_CONFIGURED fi # and some important things are there if [ ! -x "$sqlplus" ]; then ocf_log info "$sqlplus does not exist" return $OCF_ERR_INSTALLED fi if [ ! -x "$lsnrctl" ]; then ocf_log err "$lsnrctl does not exist" return $OCF_ERR_INSTALLED fi if [ ! -x "$tnsping" ]; then ocf_log err "$tnsping does not exist" return $OCF_ERR_INSTALLED fi return 0 } setoraenv() { LD_LIBRARY_PATH=$ORACLE_HOME/lib LIBPATH=$ORACLE_HOME/lib TNS_ADMIN=$ORACLE_HOME/network/admin PATH=$ORACLE_HOME/bin:$ORACLE_HOME/dbs:$PATH export ORACLE_SID ORACLE_HOME ORACLE_OWNER TNS_ADMIN export LD_LIBRARY_PATH LIBPATH } dumporaenv() { cat</dev/null } # # is_oralsnr_up: is listener process running? # oralsnr_status: is the listener running? # is_oralsnr_up() { [ x != "x`eval $procs`" ] } oralsnr_status() { output=`$lsnrctl status $listener` echo "$output" | tail -1 | grep -qs 'completed successfully' RET=$? if [ $RET -ne 0 ]; then ocf_log info "$listener status failed: $output" fi return $RET } # and does it work? tnsping() { output=`$tnsping $ORACLE_SID` echo "$output" | tail -1 | grep -qs '^OK' RET=$? if [ $RET -ne 0 ]; then ocf_log info "$tnsping $ORACLE_SID failed: $output" fi return $RET } # # oralsnr_monitor: Can we connect to the listener? # oralsnr_monitor() { if oralsnr_status && tnsping then : good #ocf_log info "Listener $listener running" return $OCF_SUCCESS else ocf_log info "Listener $listener not running" return $OCF_NOT_RUNNING fi } # # 'main' starts here... # if [ $# -ne 1 ] then usage exit $OCF_ERR_ARGS fi # These operations don't require OCF instance parameters to be set case "$1" in meta-data) meta_data exit $OCF_SUCCESS;; usage) usage exit $OCF_SUCCESS;; methods) oralsnr_methods exit $?;; *);; esac if [ x = "x$OCF_RESKEY_sid" ] then ocf_log err "Please set OCF_RESKEY_sid to the Oracle SID !" exit $OCF_ERR_ARGS fi ora_info "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user" LSB_STATUS_STOPPED=3 testoraenv rc=$? if [ $rc -ne 0 ]; then ocf_log info "Oracle environment for SID $ORACLE_SID does not exist" case "$1" in stop) exit $OCF_SUCCESS;; monitor) exit $OCF_NOT_RUNNING;; status) exit $LSB_STATUS_STOPPED;; *) ocf_log err "Oracle environment for SID $ORACLE_SID broken" exit $rc ;; esac fi setoraenv # important: set the environment for the SID envtmpf=`mktemp` dumporaenv > $envtmpf chmod 644 $envtmpf trap "rm -f $envtmpf" EXIT # # default listener is "LISTENER" # listener=${OCF_RESKEY_listener:-"LISTENER"} # how to get listener processes -procs="ps -e -o pid,args | grep '[t]nslsnr' | grep -w $listener" +procs="ps -e -o pid,user,args | grep '[t]nslsnr' | grep -w $listener | grep -w $ORACLE_OWNER" US=`id -u -n` if [ $US != root -a $US != $ORACLE_OWNER ] then ocf_log err "$0 must be run as root or $ORACLE_OWNER" exit $OCF_ERR_PERM fi # What kind of method was invoked? case "$1" in start) oralsnr_start exit $?;; stop) oralsnr_stop exit $?;; status) if oralsnr_status then echo Listener $listener is running exit $OCF_SUCCESS else echo Listener $listener is stopped exit $OCF_NOT_RUNNING fi ;; monitor) oralsnr_monitor exit $?;; validate-all) # OCF_RESKEY_sid was already checked by ora_info(), # just exit successfully here. exit $OCF_SUCCESS;; *) oralsnr_methods exit $OCF_ERR_UNIMPLEMENTED;; esac # # vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0