[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ha-dev
Subject:    Re: [Linux-ha-dev] Oracle Resource
From:       Lars Marowsky-Bree <lmb () suse ! de>
Date:       2003-03-29 21:58:49
[Download RAW message or body]

On 2003-03-28T19:21:00,
   Fernando Augusto Medeiros Silva <fams@linxplace.com.br> said:

> is there an oracle resource script?

Not yet. Providing one would be appreciated ;-)

I've attached the one we wrote for FailSafe and Oracle a while ago.


Sincerely,
    Lars Marowsky-Brée <lmb@suse.de>

-- 
SuSE Labs - Research & Development, SuSE Linux AG
  
"If anything can go wrong, it will." "Chance favors the prepared (mind)."
  -- Capt. Edward A. Murphy            -- Louis Pasteur


#!/bin/sh -xv
# 
# Control script for Oracle resource
#
# Copyright (C) 2001 SuSE Linux AG
#
# Author: Joachim Gleissner <jg@suse.de>
#
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# set some global variables
test -z "$FAILSAFE_DIR" && FAILSAFE_DIR=/usr/lib/failsafe
test -z "$SCRIPTLIB" && SCRIPTLIB=$FAILSAFE_DIR/common_scripts/scriptlib2.sh

# load the common lib
. $SCRIPTLIB || exit -1


is_db_running()
{
    # first test, check for sqlplus frontend
    if [ ! -x $BinPath/sqlplus ]; then
	if [ -z "`ps xa | grep -v grep | grep -E \"ora.*${DBName} \"`" ]; then
	    s2_log "sqlplus not found and no processes detected. Assuming resource is down."
	    return 1
	else
	    s2_log "did not found sqlplus but oracle processes for instance $DBName"
	    s2_log "check your setup! I assume resource is up."
	    return 0
	fi
    fi
    
    # also check for listener
    killall -0 tnslsnr || {
        s2_log "Listener not running, trying to start." ;
        s2_run_command -u $AdmUser -t 10 "$BinPath/lsnrctl start" ; }


    CMD=$FAILSAFE_DIR/resource_types/Oracle/check

    s2_run_command -u $AdmUser -t 10 "$CMD $BinPath $DBName" "SQL check"
				
    if [ $? -ne 0 ]; then
	s2_log "Oracle instance $DBName is not running properly."
	rm -f $EXIT_FILE
	return 1
    fi

    rm -f $EXIT_FILE
    return 0
}

do_db_cmd()
{
    CMD=$FAILSAFE_DIR/resource_types/Oracle/run_cmd
    
    s2_run_command -u $AdmUser -t 20 "$CMD $BinPath $DBName $1" "Orace instance $DBName: performing $1"

    test $? -ne 0 && return 1
    return 0
}

process_resource()
{
    action=$1
    resource_name=$2
    resource_attributes="$3"

    # get attributes
    DBName=$resource_name
    BinPath=$(s2_get_attribute_value BinPath "$resource_attributes")
    AdmUser=$(s2_get_attribute_value AdmUser "$resource_attributes")

    exit_status=0

    case $action in

	start)
	killall -0 tnslsnr || {
	    s2_log "Oracle listener not running, trying to start" ;
	    s2_run_command -u $AdmUser -t 10 "$BinPath/lsnrctl start" ; }
			
	    if ! is_db_running ; then
		do_db_cmd startup
		is_db_running
		exit_status=$?
	    else
		s2_log "Oracle instance $DBName is already running"
	    fi

	    if [ $exit_status -ne 0 ]; then
		s2_log "start of Oracle instance $DBName failed."
	    fi
	    ;;

	    stop)
	    if is_db_running ; then
		do_db_cmd shutdown
		if [ $? -ne 0 ]; then
		    s2_log "shutdown failed, trying to shutdown immediate."
		    do_db_cmd "shutdown immediate"
		    if [ $? -ne 0 ]; then
			s2_log "shutdown failed, trying to shutdown abort."
			do_db_cmd "shutdown abort"
			fi
		    fi
		is_db_running && exit_status=1
	    fi
	    ;;

	    restart)
	    killall -0 tnslsnr || {
		s2_log "Oracle listener not running, trying to start" ;
		s2_run_command -u $AdmUser -t 10 "$BinPath/lsnrctl start" ; }
	    do_db_cmd shutdown || do_db_cmd "shutdown immediate" || \
				  do_db_cmd "shutdown abort"
	    do_db_cmd "startup" || exit_status=1
	    ;;

	    monitor)
	    is_db_running
	    exit_status=$?
	    ;;
		
	    exclusive)
	    is_db_running && exit_status=1
	    ;;

	    *)
	    ;;

    esac

    if [ $exit_status -eq 0 ]; then 
        s2_write_resource_status $HA_SUCCESS $resource_name
    else
        s2_write_resource_status $HA_CMD_FAILED $resource_name
    fi
}

# Debugging output
# echo "Oracle: cmd line: $*" >/tmp/ora.log
# for i in $* ; do echo $i >> /tmp/ora.log ; cat $i >> /tmp/ora.log ; done

s2_execute


#!/bin/sh
#
# Check script for Oracle agent
#
# this script does a simple SQL query to check weather the given
# Oracle instance is available
#
# Copyright (C) 2001 SuSE Linux AG
#
# Author: Joachim Gleissner <jg@suse.de>


test -x $1/sqlplus || { echo "$1/sqlplus not found" 1>&2 ; exit 1 ; }

export ORACLE_SID=$2

echo -e 'whenever sqlerror exit failure\nselect * from GLOBAL_NAME;' \
	| $1/sqlplus internal

exit $?



#!/bin/sh
#
# run_cmd script for Oracle agent
#
# this script executes the given command(s) using
# Oracle SQLPLUS
#
# Copyright (C) 2001 SuSE Linux AG
#
# Author: Joachim Gleissner <jg@suse.de>

test -x $1/sqlplus || { echo "$1/sqlplus not found" 1>&2 ; exit 1 ; }
SQLPLUS=$1/sqlplus
shift

export ORACLE_SID=$1
shift

output=$(mktemp /tmp/runcmd_out.XXXXXXX) || exit 2

echo "$*" | $SQLPLUS internal >> $output

ERRCODE=` grep -E "ORA-.*:" $output | awk '{ print $2 }' `

test -z "$ERRCODE" && { rm -f $output ; exit 0 ; }

echo "Error $ERRCODE" 1>&2
grep -E "ORA-.*:" $output 1>&2

rm -f $output
exit 1



_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.community.tummy.com
http://lists.community.tummy.com/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic