diff --git a/rgmanager/src/resources/Makefile.am b/rgmanager/src/resources/Makefile.am index 497239554..7719f816e 100644 --- a/rgmanager/src/resources/Makefile.am +++ b/rgmanager/src/resources/Makefile.am @@ -1,117 +1,117 @@ # # Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. # # 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. # MAINTAINERCLEANFILES = Makefile.in SUBDIRS = utils -TARGET = fs.sh oracledb.sh +TARGET = fs.sh RESOURCES = service.sh ip.sh nfsclient.sh nfsexport.sh \ script.sh netfs.sh clusterfs.sh smb.sh \ apache.sh openldap.sh samba.sh mysql.sh \ postgres-8.sh tomcat-5.sh lvm.sh \ vm.sh SAPInstance SAPDatabase named.sh \ ASEHAagent.sh drbd.sh nfsserver.sh \ - tomcat-6.sh orainstance.sh oralistener.sh + tomcat-6.sh orainstance.sh oralistener.sh oracledb.sh METADATA = apache.metadata openldap.metadata samba.metadata \ mysql.metadata postgres-8.metadata \ tomcat-5.metadata named.metadata lvm.metadata \ drbd.metadata tomcat-6.metadata \ orainstance.metadata oralistener.metadata HELPERS = ocf-shellfuncs svclib_nfslock \ lvm_by_lv.sh lvm_by_vg.sh DTD = ra-api-1-modified.dtd XSL = ra2man.xsl ra2ref.xsl ra2rng.xsl RESRNG = resources.rng.head resources.rng.mid resources.rng.tail EXTRA_DIST = $(TARGET:=.in) \ $(RESOURCES) \ $(METADATA) \ $(HELPERS) \ $(DTD) \ $(XSL) \ $(RESRNG) rasdir = ${CLUSTERDATA} ras_SCRIPTS = $(TARGET) \ $(RESOURCES) \ $(HELPERS) ras_DATA = $(METADATA) rngdir = ${CLUSTERDATA}/relaxng rng_DATA = $(DTD) $(XSL) $(RESRNG) $(TARGET): cat $@.in | sed \ -e 's#@''LOGDIR@#${LOGDIR}#g' \ > $@.out chmod +x $@.out mv $@.out $@ clean-local: rm -f $(TARGET) resources.rng ras-validation: $(RESOURCES) $(TARGET) $(DTD) @echo Validating resource agent meta-data @for f in $(RESOURCES); do \ echo " $(abs_srcdir)/$$f "; \ bash $(abs_srcdir)/$$f meta-data | xmllint --dtdvalid \ $(abs_srcdir)/$(DTD) --noout -; \ if [ $$? -ne 0 ]; then exit 1; fi \ done @for f in $(TARGET); do \ echo " $(abs_builddir)/$$f "; \ bash $(abs_builddir)/$$f meta-data | xmllint --dtdvalid \ $(abs_srcdir)/$(DTD) --noout -; \ if [ $$? -ne 0 ]; then exit 1; fi \ done # # Schema maintenance. Run 'make resources.rng' and paste it in to # config/tools/xml/cluster.rng.in where it says 'autogenerated'. # # resources.rng.* should never be distributed by themselves. # resources.rng: $(RESOURCES) $(TARGET) utils/config-utils.sh resources.rng: $(XSL) $(RESRNG) rm -f resources.rng cat resources.rng.head >> resources.rng @echo Generating per-resource RelaxNG information... @for f in $(RESOURCES) $(TARGET); do \ echo " ./$$f"; \ bash ./$$f meta-data | xsltproc ra2rng.xsl - >> resources.rng; \ done cat resources.rng.mid >> resources.rng @echo Generating per-resource RelaxNG reference information... @for f in $(RESOURCES) $(TARGET); do \ echo " ./$$f"; \ bash ./$$f meta-data | xsltproc ra2ref.xsl - >> resources.rng; \ done cat resources.rng.tail >> resources.rng utils/config-utils.sh: make -C utils config-utils.sh diff --git a/rgmanager/src/resources/oracledb.sh.in b/rgmanager/src/resources/oracledb.sh similarity index 63% rename from rgmanager/src/resources/oracledb.sh.in rename to rgmanager/src/resources/oracledb.sh index 8d3c39e04..2bbb807c8 100644 --- a/rgmanager/src/resources/oracledb.sh.in +++ b/rgmanager/src/resources/oracledb.sh @@ -1,913 +1,1018 @@ #!/bin/bash # # Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved. -# Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. +# Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. # # 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. # # Author(s): # Hardy Merrill # Lon Hohberger # Michael Moon -# -# chkconfig: 345 99 01 -# description: Service script for starting/stopping \ -# Oracle(R) Database 10g on \ -# Red Hat Enterprise Linux 5 +# Ryan McCabe # # NOTES: # # (1) You can comment out the LOCKFILE declaration below. This will prevent # the need for this script to access anything outside of the ORACLE_HOME # path. # # (2) You MUST customize ORACLE_USER, ORACLE_HOME, ORACLE_SID, and # ORACLE_HOSTNAME to match your installation if not running from within # rgmanager. # # (3) Do NOT place this script in shared storage; place it in ORACLE_USER's # home directory in non-clustered environments and /usr/share/cluster # in rgmanager/Red Hat cluster environments. # # Oracle is a registered trademark of Oracle Corporation. # Oracle9i is a trademark of Oracle Corporation. # Oracle10g is a trademark of Oracle Corporation. +# Oracle11g is a trademark of Oracle Corporation. # All other trademarks are property of their respective owners. # -. /etc/init.d/functions +. $(dirname $0)/ocf-shellfuncs +. $(dirname $0)/utils/config-utils.sh +. $(dirname $0)/utils/messages.sh +. $(dirname $0)/utils/ra-skelet.sh -# -# Source stuff from /etc/sysconfig, but this may be overridden if -# this is being called as a cluster resource agent instead. -#. /etc/sysconfig/oracledb +. /etc/init.d/functions declare SCRIPT="`basename $0`" declare SCRIPTDIR="`dirname $0`" [ -n "$OCF_RESKEY_user" ] && ORACLE_USER=$OCF_RESKEY_user [ -n "$OCF_RESKEY_home" ] && ORACLE_HOME=$OCF_RESKEY_home [ -n "$OCF_RESKEY_name" ] && ORACLE_SID=$OCF_RESKEY_name [ -n "$OCF_RESKEY_listener_name" ] && ORACLE_LISTENER=$OCF_RESKEY_listener_name [ -n "$OCF_RESKEY_lockfile" ] && LOCKFILE=$OCF_RESKEY_lockfile [ -n "$OCF_RESKEY_type" ] && ORACLE_TYPE=$OCF_RESKEY_type [ -n "$OCF_RESKEY_vhost" ] && ORACLE_HOSTNAME=$OCF_RESKEY_vhost ###################################################### # Customize these to match your Oracle installation. # ###################################################### # # 1. Oracle user. Must be the same across all cluster members. In the event # that this script is run by the super-user, it will automatically switch # to the Oracle user and restart. Oracle needs to run as the Oracle # user, not as root. # #[ -n "$ORACLE_USER" ] || ORACLE_USER=oracle # # 2. Oracle home. This is set up during the installation phase of Oracle. # From the perspective of the cluster, this is generally the mount point # you intend to use as the mount point for your Oracle Infrastructure # service. # #[ -n "$ORACLE_HOME" ] || ORACLE_HOME=/mnt/oracle/home # # 3. This is your SID. This is set up during oracle installation as well. # #[ -n "$ORACLE_SID" ] || ORACLE_SID=orcl # # 4. The oracle user probably doesn't have the permission to write to # /var/lock/subsys, so use the user's home directory. # #[ -n "$LOCKFILE" ] || LOCKFILE="/home/$ORACLE_USER/.oracle-ias.lock" [ -n "$LOCKFILE" ] || LOCKFILE="$ORACLE_HOME/.oracle-ias.lock" #[ -n "$LOCKFILE" ] || LOCKFILE="/var/lock/subsys/oracle-ias" # Watch privileges # # 5. Type of Oracle Database. Currently supported: 10g 10g-iAS(untested!) # [ -n "$ORACLE_TYPE" ] || ORACLE_TYPE="base-em" # # 6. Oracle virtual hostname. This is the hostname you gave Oracle during # installation. # #[ -n "$ORACLE_HOSTNAME" ] || ORACLE_HOSTNAME=svc0.foo.test.com ########################################################################### ORACLE_TYPE=`echo $ORACLE_TYPE | tr A-Z a-z` export ORACLE_USER ORACLE_HOME ORACLE_SID LOCKFILE ORACLE_TYPE export ORACLE_HOSTNAME ########################## # Set up paths we'll use. Not all are used by all the different types of # Oracle installations # export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/opmn/lib export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/opmn/bin:$ORACLE_HOME/dcm/bin:$PATH -declare -i RESTART_RETRIES=0 +declare -i RESTART_RETRIES=3 declare -r DB_PROCNAMES="pmon" #declare -r DB_PROCNAMES="pmonXX" # testing #declare -r DB_PROCNAMES="pmon smon dbw0 lgwr" declare -r LSNR_PROCNAME="tnslsnr" #declare -r LSNR_PROCNAME="tnslsnrXX" # testing +# clulog will not log messages when run by the oracle user. +# This is a hack to work around that. +if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then + ocf_log() { + prio=$1 + shift + logger -i -p daemon."$prio" -- "$*" + } +fi ########################################################## # (Hopefully) No user-serviceable parts below this line. # ########################################################## meta_data() { cat < 1.0 - Oracle 10g Failover Instance + Oracle 10g/11g Failover Instance - Oracle 10g Failover Instance + Oracle 10g/11g Failover Instance Instance name (SID) of oracle instance Oracle SID Oracle Listener Instance Name. If you have multiple instances of Oracle running, it may be necessary to have multiple listeners on the same machine with different names. Oracle Listener Instance Name - Oracle user name. This is the user name of the Oracle user which the Oracle AS instance runs as. Oracle User Name This is the Oracle (application, not user) home directory. This is configured when you install Oracle. Oracle Home Directory This is the Oracle installation type: base - Database Instance and Listener only + base-11g - Oracle11g Database Instance and Listener Only base-em (or 10g) - Database, Listener, Enterprise Manager, and iSQL*Plus + base-em-11g - Database, Listener, Enterprise Manager dbconsole ias (or 10g-ias) - Internet Application Server (Infrastructure) Oracle Installation Type Virtual Hostname matching the installation hostname of Oracle 10g. Note that during the start/stop of an oracledb resource, your hostname will temporarily be changed to this hostname. As such, it is recommended that oracledb resources be instanced as part of an exclusive service only. Virtual Hostname EOT } - -# -# "action"-like macro supporting functions -# -faction() -{ - echo -n "$1" - shift - $* - if [ $? -eq 0 ]; then - echo_success - echo - return 0 - fi - - echo_failure - echo - return 1 -} - - # -# Start Oracle9i (database portion) +# Start Oracle9i/10g/11g (database portion) # start_db() { - declare tmpfile - declare logfile declare -i rv + declare startup_cmd + declare startup_stdout - tmpfile="$(mktemp /tmp/$SCRIPT-start.XXXXXX)" - logfile=@LOGDIR@/$SCRIPT-start.log + ocf_log info "Starting Oracle DB $ORACLE_SID" - # # Set up our sqlplus script. Basically, we're trying to # capture output in the hopes that it's useful in the case # that something doesn't work properly. - # - echo "startup" > $tmpfile - echo "quit" >> $tmpfile - - sqlplus "/ as sysdba" < $tmpfile &> $logfile + startup_cmd="set heading off;\nstartup;\nquit;\n" + startup_stdout=$(echo -e "$startup_cmd" | sqlplus -S "/ as sysdba") rv=$? - rm -f $tmpfile - - # Dump logfile to /var/log/messages - logger -f $logfile + # Dump output to syslog for debugging + ocf_log debug "[$ORACLE_SID] [$rv] sent $startup_cmd" + ocf_log debug "[$ORACLE_SID] [$rv] got $startup_stdout" if [ $rv -ne 0 ]; then - echo "ORACLE_HOME Incorrectly set?" - echo "See $logfile for more information." - return 1 + ocf_log error "Starting Oracle DB $ORACLE_SID failed, sqlplus returned $rv" + return 1 fi - # # If we see: # ORA-.....: failure, we failed - # - - rm -f $tmpfile - grep -q "^ORA-" $logfile - if [ $? -eq 0 ]; then - echo "ORACLE_SID Incorrectly set?" - rm -f $tmpfile - echo "See $logfile for more information." - return 1 + # Troubleshooting: + # ORA-00845 - Try rm -f /dev/shm/ora_* + # ORA-01081 - Try echo -e 'shutdown abort;\nquit;'|sqlplus "/ as sysdba" + if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then + ocf_log error "Starting Oracle DB $ORACLE_SID failed, found errors in stdout" + return 1 fi + ocf_log info "Started Oracle DB $ORACLE_SID successfully" return 0 } # -# Stop Oracle9i (database portion) +# Stop Oracle (database portion) # stop_db() { - declare tmpfile - declare logfile + declare stop_cmd + declare stop_stdout declare -i rv declare how_shutdown="$1" if [ -z "$1" ]; then how_shutdown="immediate" fi - tmpfile="$(mktemp /tmp/$SCRIPT-stop.XXXXXX)" - logfile=@LOGDIR@/$SCRIPT-stop.log + ocf_log info "Stopping Oracle DB $ORACLE_SID $how_shutdown" # Setup for Stop ... - echo "shutdown $how_shutdown" > $tmpfile - echo "quit" >> $tmpfile - - sqlplus "/ as sysdba" < $tmpfile &> $logfile + stop_cmd="set heading off;\nshutdown $how_shutdown;\nquit;\n" + stop_stdout=$(echo -e "$stop_cmd" | sqlplus -S "/ as sysdba") rv=$? - rm -f $tmpfile - - # Dump logfile to /var/log/messages - logger -f $logfile + # Log stdout of the stop command + ocf_log debug "[$ORACLE_SID] sent stop command $stop_cmd" + ocf_log debug "[$ORACLE_SID] got $stop_stdout" + # sqlplus returned failure. We'll return failed to rhcs if [ $rv -ne 0 ]; then - echo "ORACLE_HOME Incorrectly set?" - echo "See $logfile for more information." - return 1 + ocf_log error "Stopping Oracle DB $ORACLE_SID failed, sqlplus returned $rv" + return 1 fi - # - # If we see 'failure' in the log, we're done. - # - rm -f $tmpfile - grep -q "^ORA-" $logfile - if [ $? -eq 0 ]; then - echo_failure - echo - echo "Possible reason: ORACLE_SID Incorrectly set." - echo "See $logfile for more information." - return 1 + # If we see 'ORA-' or 'failure' in stdout, we're done. + if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then + ocf_log error "Stopping Oracle DB $ORACLE_SID failed, errors in stdout" + return 1 fi + ocf_log info "Stopped Oracle DB $ORACLE_SID successfully" return 0 } # # Destroy any remaining processes with refs to $ORACLE_HOME # force_cleanup() { declare pids declare pid # Patch from Shane Bradley to fix 471266 pids=`ps ax | grep $ORACLE_HOME | grep "ora_.*_${ORACLE_SID}" | grep -v grep | awk '{print $1}'` - logger -t $SCRIPT " Not all Oracle processes exited cleanly, killing" - + ocf_log error "Not all Oracle processes for $ORACLE_SID exited cleanly, killing" + for pid in $pids; do kill -9 $pid - if [ $? -eq 0 ]; then - logger -t $SCRIPT "Killed $pid" + rv=$? + if [ $rv -eq 0 ]; then + ocf_log info "Cleanup $ORACLE_SID Killed PID $pid" + else + ocf_log error "Cleanup $ORACLE_SID Kill PID $pid failed: $rv" fi done return 0 } # # Wait for oracle processes to exit. Time out after 60 seconds # exit_idle() { declare -i n=0 + + ocf_log debug "Waiting for Oracle processes for $ORACLE_SID to terminate..." while ps ax | grep $ORACLE_HOME | grep -q -v grep; do if [ $n -ge 90 ]; then + ocf_log debug "Timed out while waiting for Oracle processes for $ORACLE_SID to terminate" force_cleanup return 0 fi sleep 1 ((n++)) done + + ocf_log debug "All Oracle processes for $ORACLE_SID have terminated" return 0 } # # Get database background process status. Restart it if it failed and # we have seen the lock file. # get_db_status() { declare -i subsys_lock=$1 declare -i i=0 declare -i rv=0 declare ora_procname for procname in $DB_PROCNAMES ; do ora_procname="ora_${procname}_${ORACLE_SID}" status $ora_procname if [ $? -eq 0 ] ; then # This one's okay; go to the next one. continue fi # # We're not supposed to be running, and we are, # in fact, not running... # XXX only works when monitoring one db process; consider # extending in future. # if [ $subsys_lock -ne 0 ]; then return 3 fi for (( i=$RESTART_RETRIES ; i; i-- )) ; do # this db process is down - stop and # (re)start all ora_XXXX_$ORACLE_SID processes - logger -t $SCRIPT "Restarting Oracle Database..." + ocf_log info "Restarting Oracle Database $ORACLE_SID" stop_db immediate - if [ $? != 0 ] ; then + if [ $? -ne 0 ] ; then # stop failed - return 1 + ocf_log error "Error stopping Oracle Database $ORACLE_SID" return 1 fi start_db - if [ $? == 0 ] ; then + if [ $? -eq 0 ] ; then # ora_XXXX_$ORACLE_SID processes started # successfully, so break out of the # stop/start # 'for' loop + ocf_log info "Restarted Oracle Database $ORACLE_SID successfully" break fi done if [ $i -eq 0 ]; then # stop/start's failed - return 1 (failure) + ocf_log error "Failed to restart Oracle Database $ORACLE_SID after $RESTART_RETRIES tries" return 1 fi done return 0 } # # Get the status of the Oracle listener process # get_lsnr_status() { declare -i subsys_lock=$1 declare -i rv - status $LSNR_PROCNAME + ocf_log debug "Checking status for listener $ORACLE_LISTENER" + lsnrctl status "$ORACLE_LISTENER" >& /dev/null rv=$? - if [ $rv == 0 ] ; then + if [ $rv -eq 0 ] ; then + ocf_log debug "Listener $ORACLE_LISTENER is up" return 0 # Listener is running fine fi - # # We're not supposed to be running, and we are, # in fact, not running. Return 3 - # if [ $subsys_lock -ne 0 ]; then + ocf_log debug "Listener $ORACLE_LISTENER is stopped as expected" return 3 fi - # # Listener is NOT running (but should be) - try to restart - # for (( i=$RESTART_RETRIES ; i; i-- )) ; do - - action "Restarting Oracle listener:" lsnrctl start \ - $ORACLE_LISTENER - lsnrctl status $ORACLE_LISTENER >& /dev/null - if [ $? == 0 ] ; then + ocf_log info "Listener $ORACLE_LISTENER is down, attempting to restart" + lsnrctl start "$ORACLE_LISTENER" >& /dev/null + lsnrctl status "$ORACLE_LISTENER" >& /dev/null + if [ $? -eq 0 ] ; then + ocf_log info "Listener $ORACLE_LISTENER was restarted successfully" break # Listener was (re)started and is running fine fi done if [ $i -eq 0 ]; then # stop/start's failed - return 1 (failure) + ocf_log error "Failed to restart listener $ORACLE_LISTENER after $RESTART_RETRIES tries" return 1 fi - status $LSNR_PROCNAME - if [ $? != 0 ] ; then + lsnrctl_stdout=$(lsnrctl status "$ORACLE_LISTENER") + rv=$? + if [ $rv -ne 0 ] ; then + ocf_log error "Starting listener $ORACLE_LISTENER failed: $rv output $lsnrctl_stdout" return 1 # Problem restarting the Listener fi + + ocf_log info "Listener $ORACLE_LISTENER started successfully" return 0 # Success restarting the Listener } # # usage: get_opmn_proc_status [process-type] # # Get the status of a specific OPMN-managed process. If process-type # is not specified, assume the process-type is the same as the ias-component. # If the lock-file exists (or no lock file is specified), try to restart # the given process-type if it is not running. # get_opmn_proc_status() { declare comp=$1 declare opmntype=$2 declare type_pretty declare _pid _status [ -n "$comp" ] || return 1 if [ -z "$opmntype" ]; then opmntype=$comp else type_pretty=" [$opmntype]" fi for (( i=$RESTART_RETRIES ; i; i-- )) ; do _status=`opmnctl status | grep "^$comp " | grep " $opmntype " | cut -d '|' -f3,4 | sed -e 's/ //g' -e 's/|/ /g'` _pid=`echo $_status | cut -f1 -d' '` _status=`echo $_status | cut -f2 -d' '` if [ "${_status}" == "Alive" ] || [ "${_status}" == "Init" ]; then if [ $i -lt $RESTART_RETRIES ] ; then - echo " $comp$type_pretty restarted" + ocf_log info "$comp$type_pretty restarted" fi - echo " $comp$type_pretty (pid $_pid) is running..." + ocf_log info "$comp$type_pretty (pid $_pid) is running..." break else - echo " $comp$type_pretty is stopped" + ocf_log info "$comp$type_pretty is stopped" # # Try to restart it, but don't worry if we fail. OPMN # is supposed to handle restarting these anyway. # # If it's running and you tell OPMN to "start" it, # you will get an error. # # If it's NOT running and you tell OPMN to "restart" # it, you will also get an error. # opmnctl startproc process-type=$opmntype &> /dev/null fi done if [ $i -eq 0 ]; then # restarts failed - return 1 (failure) + ocf_log error "Failed to restart OPMN process $comp" return 1 fi return 0 } # # Get the status of the OPMN-managed processes. # get_opmn_status() { declare -i subsys_lock=$1 declare -i ct_errors=0 opmnctl status &> /dev/null if [ $? -eq 2 ]; then # # OPMN not running?? # - echo "opmn is stopped" + ocf_log info "OPMN is stopped" if [ $subsys_lock -eq 0 ]; then # # Don't handle full opmn-restart. XXX # return 1 fi # That's okay, it's not supposed to be! return 3 fi # # Print out the PIDs for everyone. # - echo "opmn is running..." - echo "opmn components:" + ocf_log info "OPMN is running..." + ocf_log info "opmn components:" # # Check the OPMN-managed processes # get_opmn_proc_status OID || ((ct_errors++)) get_opmn_proc_status HTTP_Server || ((ct_errors++)) get_opmn_proc_status OC4J OC4J_SECURITY || ((ct_errors++)) # # One or more OPMN-managed processes failed and could not be # restarted. # if [ $ct_errors -ne 0 ]; then + ocf_log error "$ct_errors errors occurred while restarting OPMN-managed processes" return 1 fi return 0 } # # Helps us keep a running status so we know what our ultimate return # code will be. Returns 1 if the $1 and $2 are not equivalent, otherwise # returns $1. The return code is meant to be the next $1 when this is # called, so, for example: # # update_status 0 <-- returns 0 # update_status $? 0 <-- returns 0 # update_status $? 3 <-- returns 1 (values different - error condition) # update_status $? 1 <-- returns 1 (same, but happen to be error state!) # # update_status 3 # update_status $? 3 <-- returns 3 # # (and so forth...) # update_status() { declare -i old_status=$1 declare -i new_status=$2 if [ -z "$2" ]; then return $old_status fi if [ $old_status -ne $new_status ]; then return 1 fi return $old_status } # # Print an error message to the user and exit. # oops() { - echo "Please configure this script ($0) to" - echo "match your installation." - echo - echo " $1 failed validation checks." + ocf_log error "$ORACLE_SID: Fatal: $1 failed validation checks" exit 1 } # # Do some validation on the user-configurable stuff at the beginning of the # script. # validation_checks() { + ocf_log debug "Validating configuration for $ORACLE_SID" + # # If the oracle user doesn't exist, we're done. # [ -n "$ORACLE_USER" ] || oops "ORACLE_USER" id -u $ORACLE_USER > /dev/null || oops "ORACLE_USER" id -g $ORACLE_USER > /dev/null || oops "ORACLE_USER" # # If the oracle home isn't a directory, we're done # [ -n "$ORACLE_HOME" ] || oops ORACLE_HOME #[ -d "$ORACLE_HOME" ] || oops ORACLE_HOME # # If the oracle SID is NULL, we're done # [ -n "$ORACLE_SID" ] || oops ORACLE_SID # # If we don't know the type, we're done # if [ "$ORACLE_TYPE" = "base" ]; then # Other names for base ORACLE_TYPE="base" elif [ "$ORACLE_TYPE" = "10g" ] || [ "$ORACLE_TYPE" = "base-em" ]; then ORACLE_TYPE="base-em" elif [ "$ORACLE_TYPE" = "10g-ias" ] || [ "$ORACLE_TYPE" = "ias" ]; then ORACLE_TYPE="ias" + elif [ "$ORACLE_TYPE" = "11g" ] || [ "$ORACLE_TYPE" = "base-em-11g" ]; then + ORACLE_TYPE="base-em-11g" + elif [ "$ORACLE_TYPE" = "base-11g" ]; then + ORACLE_TYPE="base-11g" else - oops ORACLE_TYPE + oops "ORACLE_TYPE $ORACLE_TYPE" fi # # If the hostname is zero-length, fix it # [ -n "$ORACLE_HOSTNAME" ] || ORACLE_HOSTNAME=`hostname` # # Super user? Automatically change UID and exec as oracle user. # Oracle needs to be run as the Oracle user, not root! # if [ "`id -u`" = "0" ]; then - echo "Restarting $0 as $ORACLE_USER." + #echo "Restarting $0 as $ORACLE_USER." # # Breaks on RHEL5 # exec sudo -u $ORACLE_USER $0 $* # su $ORACLE_USER -c "$0 $*" exit $? fi # # If we're not root and not the Oracle user, we're done. # - [ "`id -u`" = "`id -u $ORACLE_USER`" ] || exit 1 - [ "`id -g`" = "`id -g $ORACLE_USER`" ] || exit 1 + [ "`id -u`" = "`id -u $ORACLE_USER`" ] || oops "not ORACLE_USER after su" + [ "`id -g`" = "`id -g $ORACLE_USER`" ] || oops "not ORACLE_GROUP after su" # # Go home. # - cd $ORACLE_HOME + cd "$ORACLE_HOME" + ocf_log debug "Validation checks for $ORACLE_SID succeeded" return 0 } # -# Start Oracle9i Application Server Infrastructure +# Start Oracle 9i/10g/11g Application Server Infrastructure # start_oracle() { - faction "Starting Oracle Database:" start_db || return 1 - action "Starting Oracle Listener:" lsnrctl start $ORACLE_LISTENER || return 1 + ocf_log info "Starting service $ORACLE_SID" + + start_db + rv=$? + if [ $rv -ne 0 ]; then + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + fi + + ocf_log info "Starting listener $ORACLE_LISTENER" + lsnrctl_stdout=$(lsnrctl start "$ORACLE_LISTENER") + rv=$? + if [ $rv -ne 0 ]; then + ocf_log debug "[$ORACLE_SID] Listener $ORACLE_LISTENER start returned $rv output $lsnrctl_stdout" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + fi if [ "$ORACLE_TYPE" = "base-em" ]; then - action "Starting iSQL*Plus:" isqlplusctl start || return 1 - action "Starting Oracle EM DB Console:" emctl start dbconsole || return 1 + ocf_log info "Starting iSQL*Plus for $ORACLE_SID" + isqlplusctl start + if [ $? -ne 0 ]; then + ocf_log error "iSQL*Plus startup for $ORACLE_SID failed" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + else + ocf_log info "iSQL*Plus startup for $ORACLE_SID succeeded" + fi + + ocf_log info "Starting Oracle EM DB Console for $ORACLE_SID" + emctl start dbconsole + if [ $? -ne 0 ]; then + ocf_log error "Oracle EM DB Console startup for $ORACLE_SID failed" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + else + ocf_log info "Oracle EM DB Console startup for $ORACLE_SID succeeded" + fi elif [ "$ORACLE_TYPE" = "ias" ]; then - action "Starting Oracle EM:" emctl start em || return 1 - action "Starting iAS Infrastructure:" opmnctl startall || return 1 + ocf_log info "Starting Oracle EM for $ORACLE_SID" + emctl start em + if [ $? -ne 0 ]; then + ocf_log error "Oracle EM startup for $ORACLE_SID failed" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + else + ocf_log info "Oracle EM startup for $ORACLE_SID succeeded" + fi + + ocf_log info "Starting iAS Infrastructure for $ORACLE_SID" + opmnctl startall + if [ $? -ne 0 ]; then + ocf_log error "iAS Infrastructure startup for $ORACLE_SID failed" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + else + ocf_log info "iAS Infrastructure startup for $ORACLE_SID succeeded" + fi + elif [ "$ORACLE_TYPE" = "base-em-11g" ]; then + ocf_log info "Starting Oracle EM DB Console for $ORACLE_SID" + emctl start dbconsole + if [ $? -ne 0 ]; then + ocf_log error "Oracle EM DB Console startup for $ORACLE_SID failed" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + else + ocf_log info "Oracle EM DB Console startup for $ORACLE_SID succeeded" + fi fi if [ -n "$LOCKFILE" ]; then - touch $LOCKFILE + touch "$LOCKFILE" fi + + ocf_log info "Starting service $ORACLE_SID completed successfully" return 0 } # -# Stop Oracle9i Application Server Infrastructure +# Stop Oracle 9i/10g/11g Application Server Infrastructure # stop_oracle() { + ocf_log info "Stopping service $ORACLE_SID" + if ! [ -e "$ORACLE_HOME/bin/lsnrctl" ]; then - echo "Oracle Listener Control is not available" - echo " ($ORACLE_HOME not mounted?)" + ocf_log error "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)" return 0 fi if [ "$ORACLE_TYPE" = "base-em" ]; then - action "Stopping Oracle EM DB Console:" emctl stop dbconsole || return 1 - action "Stopping iSQL*Plus:" isqlplusctl stop || return 1 + ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID" + emctl stop dbconsole + if [ $? -ne 0 ]; then + ocf_log error "Stopping Oracle EM DB Console for $ORACLE_SID failed" + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 + else + ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID succeeded" + fi + + ocf_log info "Stopping iSQL*Plus for $ORACLE_SID" + isqlplusctl stop + if [ $? -ne 0 ]; then + ocf_log error "Stopping iSQL*Plus for $ORACLE_SID failed" + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 + else + ocf_log info "Stopping iSQL*Plus for $ORACLE_SID succeeded" + fi elif [ "$ORACLE_TYPE" = "ias" ]; then - action "Stopping iAS Infrastructure:" opmnctl stopall || return 1 - action "Stopping Oracle EM:" emctl stop em || return 1 + ocf_log info "Stopping iAS Infrastructure for $ORACLE_SID" + opmnctl stopall + if [ $? -ne 0 ]; then + ocf_log error "Stopping iAS Infrastructure for $ORACLE_SID failed" + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 + else + ocf_log info "Stopping iAS Infrastructure for $ORACLE_SID succeeded" + fi + + ocf_log info "Stopping Oracle EM for $ORACLE_SID" + emctl stop em + if [ $? -ne 0 ]; then + ocf_log error "Stopping Oracle EM for $ORACLE_SID failed" + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 + else + ocf_log info "Stopping Oracle EM for $ORACLE_SID succeeded" + fi + elif [ "$ORACLE_TYPE" = "base-em-11g" ]; then + ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID" + emctl stop dbconsole + if [ $? -ne 0 ]; then + ocf_log error "Stopping Oracle EM DB Console for $ORACLE_SID failed" + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 + else + ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID succeeded" + fi fi - faction "Stopping Oracle Database:" stop_db immediate + stop_db immediate || stop_db abort if [ $? -ne 0 ]; then - faction "Stopping Oracle Database (hard):" stop_db abort || return 1 + ocf_log error "Stopping service $ORACLE_SID failed" + return 1 fi - action "Stopping Oracle Listener:" lsnrctl stop $ORACLE_LISTENER - faction "Waiting for all Oracle processes to exit:" exit_idle + ocf_log info "Stopping listener $ORACLE_LISTENER for $ORACLE_SID" + lsnrctl_stdout=$(lsnrctl stop "$ORACLE_LISTENER") + rv=$? + if [ $? -ne 0 ]; then + ocf_log error "Listener $ORACLE_LISTENER stop failed for $ORACLE_SID: $rv output $lsnrctl_stdout" + # XXX - failure? + fi + exit_idle if [ $? -ne 0 ]; then - echo "WARNING: Not all Oracle processes exited cleanly" + ocf_log warning "WARNING: Not all Oracle processes exited cleanly for $ORACLE_SID" fi if [ -n "$LOCKFILE" ]; then - rm -f $LOCKFILE + rm -f "$LOCKFILE" fi + + ocf_log info "Stopping service $ORACLE_SID succeeded" return 0 } # # Find and display the status of iAS infrastructure. # # This has three parts: # (1) Oracle database itself # (2) Oracle listener process # (3) OPMN and OPMN-managed processes # # - If all are (cleanly) down, we return 3. In order for this to happen, # $LOCKFILE must not exist. In this case, we try and restart certain parts # of the service - as this may be running in a clustered environment. # # - If some but not all are running (and, if $LOCKFILE exists, we could not # restart the failed portions), we return 1 (ERROR) # # - If all are running, return 0. In the "all-running" case, we recreate # $LOCKFILE if it does not exist. # status_oracle() { declare -i subsys_lock=1 declare -i last + ocf_log debug "Checking status for $ORACLE_SID depth $depth" + # # Check for lock file. Crude and rudimentary, but it works # - if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then + if [ -z "$LOCKFILE" ] || [ -f "$LOCKFILE" ]; then subsys_lock=0 fi # Check database status get_db_status $subsys_lock update_status $? # Start last=$? # Check & report listener status get_lsnr_status $subsys_lock update_status $? $last last=$? - if [ "$ORACLE_TYPE" = "base-em" ]; then + if [ "$ORACLE_TYPE" = "base-em" ] || [ "$ORACLE_TYPE" = "base-em-11g" ]; then # XXX Add isqlplus status check?! - emctl status dbconsole 2>&1 | grep "is running" + emctl status dbconsole >&/dev/null update_status $? $last last=$? elif [ "$ORACLE_TYPE" = "ias" ]; then # Check & report opmn / opmn-managed process status get_opmn_status $subsys_lock update_status $? $last last=$? fi # # No lock file, but everything's running. Put the lock # file back. XXX - this kosher? # if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then - touch $LOCKFILE + touch "$LOCKFILE" fi + ocf_log debug "Status returning $last for $ORACLE_SID" return $last } ######################## # Do some real work... # ######################## if [ "$1" = "meta-data" ]; then meta_data exit 0 fi validation_checks $* case $1 in start) start_oracle exit $? ;; stop) stop_oracle exit $? ;; status|monitor) status_oracle exit $? ;; restart) $0 stop || exit $? $0 start || exit $? exit 0 ;; *) echo "usage: $SCRIPT {start|stop|status|restart|meta-data}" exit 1 ;; esac exit 0 diff --git a/rgmanager/src/resources/orainstance.sh b/rgmanager/src/resources/orainstance.sh index 3d4c12349..ac71a927b 100755 --- a/rgmanager/src/resources/orainstance.sh +++ b/rgmanager/src/resources/orainstance.sh @@ -1,526 +1,576 @@ #!/bin/bash # -# Copyright 2003-2004, 2006-2011 Red Hat, Inc. +# Copyright 2003-2004, 2006-2013 Red Hat, Inc. # # Author(s): # Hardy Merrill # Lon Hohberger # Michael Moon +# Ryan McCabe # # This program is Open Source software. You may modify and/or redistribute # it persuant to the terms of the Open Software License version 2.1, which # is available from the following URL and is included herein by reference: # # http://opensource.org/licenses/osl-2.1.php # -# chkconfig: 345 99 01 -# description: Service script for starting/stopping \ -# Oracle(R) Database 10g on \ -# Red Hat Enterprise Linux 5 -# # NOTES: # # (1) You can comment out the LOCKFILE declaration below. This will prevent # the need for this script to access anything outside of the ORACLE_HOME # path. # # (2) You MUST customize ORACLE_USER, ORACLE_HOME, ORACLE_SID, and # ORACLE_HOSTNAME to match your installation if not running from within # rgmanager. # # (3) Do NOT place this script in shared storage; place it in ORACLE_USER's # home directory in non-clustered environments and /usr/share/cluster # in rgmanager/Red Hat cluster environments. # # Oracle is a registered trademark of Oracle Corporation. # Oracle9i is a trademark of Oracle Corporation. # Oracle10g is a trademark of Oracle Corporation. +# Oracle11g is a trademark of Oracle Corporation. # All other trademarks are property of their respective owners. # # # $Id: orainstance.sh 127 2009-08-21 09:17:52Z hevirtan $ # # Original version is distributed with RHCS. The modifications include # the following minor changes: # - Meta-data moved to a dedicated file # - Support for multiple listeners # - Disabled EM # - SysV init support removed. Only usable with rgmanager # +# Grab the global RHCS helper functions +. $(dirname $0)/ocf-shellfuncs +. $(dirname $0)/utils/config-utils.sh +. $(dirname $0)/utils/messages.sh +. $(dirname $0)/utils/ra-skelet.sh + . /etc/init.d/functions declare SCRIPT="`basename $0`" declare SCRIPTDIR="`dirname $0`" # Required parameters from rgmanager ORACLE_USER=$OCF_RESKEY_user ORACLE_HOME=$OCF_RESKEY_home ORACLE_SID=$OCF_RESKEY_name # Optional parameters with default values LISTENERS=$OCF_RESKEY_listeners -LOCKFILE="/tmp/.oracle10g-${ORACLE_SID}.lock" +LOCKFILE="$ORACLE_HOME/.orainstance-${ORACLE_SID}.lock" [ -n "$OCF_RESKEY_lockfile" ] && LOCKFILE=$OCF_RESKEY_lockfile export LISTENERS ORACLE_USER ORACLE_HOME ORACLE_SID LOCKFILE export LD_LIBRARY_PATH=$ORACLE_HOME/lib -export PATH=$ORACLE_HOME/bin:$PATH +export PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin declare -i RESTART_RETRIES=3 declare -r DB_PROCNAMES="pmon" declare -r LSNR_PROCNAME="tnslsnr" +# clulog will not log messages when run by the oracle user. +# This is a hack to work around that. +if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then + ocf_log() { + prio=$1 + shift + logger -i -p daemon."$prio" -- "$*" + } +fi # # Start Oracle (database portion) # start_db() { - declare tmpfile - declare logfile declare -i rv + declare startup_cmd + declare startup_stdout - tmpfile=/tmp/$SCRIPT-start.$$ - logfile=/tmp/$SCRIPT-start.log.$$ + ocf_log info "Starting Oracle DB $ORACLE_SID" # Set up our sqlplus script. Basically, we're trying to # capture output in the hopes that it's useful in the case # that something doesn't work properly. - echo "startup" > $tmpfile - echo "quit" >> $tmpfile - - sqlplus "/ as sysdba" < $tmpfile > $logfile + startup_cmd="set heading off;\nstartup;\nquit;\n" + startup_stdout=$(echo -e "$startup_cmd" | sqlplus -S "/ as sysdba") rv=$? - rm -f $tmpfile - - # Dump logfile to /var/log/messages - initlog -q -c "cat $logfile" + # Dump output to syslog for debugging + ocf_log debug "[$ORACLE_SID] [$rv] sent $startup_cmd" + ocf_log debug "[$ORACLE_SID] [$rv] got $startup_stdout" if [ $rv -ne 0 ]; then - rm -f $logfile - initlog -n $SCRIPT -q -s "sqlplus returned 1, failed" + ocf_log error "Starting Oracle DB $ORACLE_SID failed, sqlplus returned $rv" return 1 fi # If we see: # ORA-.....: failure, we failed - grep -q "^ORA-" $logfile - rv=$? - - rm -f $logfile - if [ $rv -eq 0 ]; then - initlog -n $SCRIPT -q -s "found failure in stdout, returning 1" + # Troubleshooting: + # ORA-00845 - Try rm -f /dev/shm/ora_* + # ORA-01081 - Try echo -e 'shutdown abort;\nquit;'|sqlplus "/ as sysdba" + if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then + ocf_log error "Starting Oracle DB $ORACLE_SID failed, found errors in stdout" return 1 fi + ocf_log info "Started Oracle DB $ORACLE_SID successfully" return 0 } # # Stop Oracle (database portion) # stop_db() { - declare tmpfile - declare logfile + declare stop_cmd + declare stop_stdout declare -i rv + declare how_shutdown="$1" - tmpfile=/tmp/$SCRIPT-stop.$$ - logfile=/tmp/$SCRIPT-stop.log.$$ + if [ -z "$1" ]; then + how_shutdown="immediate" + fi - ora_procname="ora_${DB_PROCNAMES}_${ORACLE_SID}" - status $ora_procname - if [ $? -ne 0 ]; then - # No pmon process found, db already down - return 0 - fi + ocf_log info "Stopping Oracle DB $ORACLE_SID $how_shutdown" - # Setup for Stop ... - echo "shutdown immediate" > $tmpfile - echo "quit" >> $tmpfile + ora_procname="ora_${DB_PROCNAMES}_${ORACLE_SID}" + status $ora_procname + if [ $? -ne 0 ]; then + ocf_log debug "no pmon process -- DB $ORACLE_SID already stopped" + # No pmon process found, db already down + return 0 + fi - sqlplus "/ as sysdba" < $tmpfile > $logfile + # Setup for Stop ... + stop_cmd="set heading off;\nshutdown $how_shutdown;\nquit;\n" + stop_stdout=$(echo -e "$stop_cmd" | sqlplus -S "/ as sysdba") rv=$? - rm -f $tmpfile - - # Dump logfile to /var/log/messages - initlog -q -c "cat $logfile" + # Log stdout of the stop command + ocf_log debug "[$ORACLE_SID] sent stop command $stop_cmd" + ocf_log debug "[$ORACLE_SID] got $stop_stdout" - # sqlplus returned failure. We'll return failed to rhcs + # sqlplus returned failure. We'll return failed to rhcs if [ $rv -ne 0 ]; then - rm -f $logfile - initlog -n $SCRIPT -q -s "sqlplus returned 1, failed" + ocf_log error "Stopping Oracle DB $ORACLE_SID failed, sqlplus returned $rv" return 1 fi - grep -q "^ORA-" $logfile - rv=$? - rm -f $logfile - - # If we see 'failure' in the log, we're done. - if [ $rv -eq 0 ]; then - initlog -n $SCRIPT -q -s "found failure in stdout, returning 1" + # If we see 'ORA-' or 'failure' in stdout, we're done. + if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then + ocf_log error "Stopping Oracle DB $ORACLE_SID failed, errors in stdout" return 1 fi + ocf_log info "Stopped Oracle DB $ORACLE_SID successfully" return 0 } # # Destroy any remaining processes with refs to $ORACLE_SID # force_cleanup() { declare pids declare pid - pids=`ps ax | grep $ORACLE_SID | grep -v grep | awk '{print $1}'` - - initlog -n $SCRIPT -s " Not all Oracle processes exited cleanly, killing" + ocf_log error "Not all Oracle processes for $ORACLE_SID exited cleanly, killing" + pids=`ps ax | grep "ora_.*_${ORACLE_SID}" | grep -v grep | awk '{print $1}'` + for pid in $pids; do kill -9 $pid - if [ $? -eq 0 ]; then - initlog -n $SCRIPT -s "Killed $pid" + rv=$? + if [ $rv -eq 0 ]; then + ocf_log info "Cleanup $ORACLE_SID Killed PID $pid" + else + ocf_log error "Cleanup $ORACLE_SID Kill PID $pid failed: $rv" fi done return 0 } # # Wait for oracle processes to exit. Time out after 60 seconds # exit_idle() { declare -i n=0 + ocf_log debug "Waiting for Oracle processes for $ORACLE_SID to terminate..." while ps ax | grep $ORACLE_SID | grep -q -v $LSNR_PROCNAME | grep -q -v grep; do if [ $n -ge 90 ]; then + ocf_log debug "Timed out while waiting for Oracle processes for $ORACLE_SID to terminate" force_cleanup return 0 fi sleep 1 ((n++)) done + + ocf_log debug "All Oracle processes for $ORACLE_SID have terminated" return 0 } # # Get database background process status. Restart it if it failed and # we have seen the lock file. # get_db_status() { declare -i subsys_lock=$1 declare -i i=0 declare -i rv=0 declare ora_procname + ocf_log debug "Checking status of DB $ORACLE_SID" + for procname in $DB_PROCNAMES ; do ora_procname="ora_${procname}_${ORACLE_SID}" status $ora_procname if [ $? -eq 0 ] ; then # This one's okay; go to the next one. continue fi # We're not supposed to be running, and we are, # in fact, not running... if [ $subsys_lock -ne 0 ]; then + ocf_log debug "DB $ORACLE_SID is already stopped" return 3 fi for (( i=$RESTART_RETRIES ; i; i-- )) ; do # this db process is down - stop and # (re)start all ora_XXXX_$ORACLE_SID processes - initlog -q -n $SCRIPT -s "Restarting Oracle Database..." + ocf_log info "Restarting Oracle Database $ORACLE_SID" stop_db start_db - if [ $? == 0 ] ; then + if [ $? -eq 0 ] ; then # ora_XXXX_$ORACLE_SID processes started # successfully, so break out of the # stop/start # 'for' loop + ocf_log info "Restarted Oracle DB $ORACLE_SID successfully" break fi done if [ $i -eq 0 ]; then # stop/start's failed - return 1 (failure) - initlog -q -n $SCRIPT -s "Restart failed, retuning 1" + ocf_log error "Failed to restart Oracle DB $ORACLE_SID after $RESTART_RETRIES tries" return 1 fi done + + ocf_log debug "Checking status of DB $ORACLE_SID success" return 0 } # # Get the status of the Oracle listener process # get_lsnr_status() { declare -i subsys_lock=$1 declare -i rv - declare -r LISTENER=$3 + declare -r LISTENER=$3 - lsnrctl status $LISTENER >& /dev/null + ocf_log debug "Checking status for listener $LISTENER" + lsnrctl status "$LISTENER" >& /dev/null rv=$? - if [ $rv == 0 ] ; then + if [ $rv -eq 0 ] ; then + ocf_log debug "Listener $LISTENER is up" return 0 # Listener is running fine fi # We're not supposed to be running, and we are, # in fact, not running. Return 3 if [ $subsys_lock -ne 0 ]; then + ocf_log debug "Listener $LISTENER is stopped as expected" return 3 fi # Listener is NOT running (but should be) - try to restart for (( i=$RESTART_RETRIES ; i; i-- )) ; do - initlog -n $SCRIPT -q -s "Restarting Oracle listener ($LISTENER)" - lsnrctl start $LISTENER - lsnrctl status $LISTENER >& /dev/null - if [ $? == 0 ] ; then + ocf_log info "Listener $LISTENER is down, attempting to restart" + lsnrctl start "$LISTENER" >& /dev/null + lsnrctl status "$LISTENER" >& /dev/null + if [ $? -eq 0 ]; then + ocf_log info "Listener $LISTENER was restarted successfully" break # Listener was (re)started and is running fine fi done if [ $i -eq 0 ]; then # stop/start's failed - return 1 (failure) - initlog -n $SCRIPT -q -s "Listener restart failed, retuning 1" + ocf_log error "Failed to restart listener $LISTENER after $RESTART_RETRIES tries" return 1 fi - lsnrctl status $LISTENER >& /dev/null - if [ $? != 0 ] ; then - initlog -n $SCRIPT -q -s "Listener status failed, retuning 1" + lsnrctl_stdout=$(lsnrctl status "$LISTENER") + rv=$? + if [ $rv -ne 0 ] ; then + ocf_log error "Starting listener $LISTENER failed: $rv output $lsnrctl_stdout" return 1 # Problem restarting the Listener fi + + ocf_log info "Listener $LISTENER started successfully" return 0 # Success restarting the Listener } # # Helps us keep a running status so we know what our ultimate return # code will be. Returns 1 if the $1 and $2 are not equivalent, otherwise # returns $1. The return code is meant to be the next $1 when this is # called, so, for example: # # update_status 0 <-- returns 0 # update_status $? 0 <-- returns 0 # update_status $? 3 <-- returns 1 (values different - error condition) # update_status $? 1 <-- returns 1 (same, but happen to be error state!) # # update_status 3 # update_status $? 3 <-- returns 3 # # (and so forth...) # update_status() { declare -i old_status=$1 declare -i new_status=$2 if [ -z "$2" ]; then return $old_status fi if [ $old_status -ne $new_status ]; then - initlog -n $SCRIPT -q -s "$old_status vs $new_status - returning 1" + ocf_log error "Error: $old_status vs $new_status for $ORACLE_SID - returning 1" return 1 fi return $old_status } # # Print an error message to the user and exit. # oops() { - #echo "Please configure this script ($0) to" - #echo "match your installation." - #echo - #echo " $1 failed validation checks." - initlog -n $SCRIPT -q -s "$1 failed validation checks" + ocf_log error "$ORACLE_SID: Fatal: $1 failed validation checks" exit 1 } # # Do some validation on the user-configurable stuff at the beginning of the # script. # validation_checks() { + ocf_log debug "Validating configuration for $ORACLE_SID" + # If the oracle user doesn't exist, we're done. [ -n "$ORACLE_USER" ] || oops "ORACLE_USER" id -u $ORACLE_USER > /dev/null || oops "ORACLE_USER" - id -g $ORACLE_USER > /dev/null || oops "ORACLE_USER" + id -g $ORACLE_USER > /dev/null || oops "ORACLE_GROUP" # If the oracle home isn't a directory, we're done - [ -n "$ORACLE_HOME" ] || oops ORACLE_HOME + [ -n "$ORACLE_HOME" ] || oops "ORACLE_HOME" # If the oracle SID is NULL, we're done - [ -n "$ORACLE_SID" ] || oops ORACLE_SID + [ -n "$ORACLE_SID" ] || oops "ORACLE_SID" # Super user? Automatically change UID and exec as oracle user. # Oracle needs to be run as the Oracle user, not root! if [ "`id -u`" = "0" ]; then su $ORACLE_USER -c "$0 $*" exit $? fi # If we're not root and not the Oracle user, we're done. - [ "`id -u`" = "`id -u $ORACLE_USER`" ] || exit 1 - [ "`id -g`" = "`id -g $ORACLE_USER`" ] || exit 1 + [ "`id -u`" = "`id -u $ORACLE_USER`" ] || oops "not ORACLE_USER after su" + [ "`id -g`" = "`id -g $ORACLE_USER`" ] || oops "not ORACLE_GROUP after su" # Go home. - cd $ORACLE_HOME + cd "$ORACLE_HOME" + ocf_log debug "Validation checks for $ORACLE_SID succeeded" return 0 } # # Start Oracle # start_oracle() { - initlog -n $SCRIPT -q -s "Starting Oracle Database" - start_db || return 1 - - for LISTENER in ${LISTENERS}; do - logfile=/tmp/$SCRIPT-lsn-$$.log - initlog -n $SCRIPT -q -s "Starting Oracle Listener $LISTENER" - lsnrctl start $LISTENER > $logfile - initlog -q -c "cat $logfile" - rm -f $logfile - done + ocf_log info "Starting service $ORACLE_SID" + + start_db + rv=$? + if [ $rv -ne 0 ]; then + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + fi + + for LISTENER in ${LISTENERS}; do + ocf_log info "Starting listener $LISTENER" + lsnrctl_stdout=$(lsnrctl start "$LISTENER") + rv=$? + if [ $rv -ne 0 ]; then + ocf_log debug "[$ORACLE_SID] Listener $LISTENER start returned $rv output $lsnrctl_stdout" + ocf_log error "Starting service $ORACLE_SID failed" + return 1 + fi + done if [ -n "$LOCKFILE" ]; then - touch $LOCKFILE + touch "$LOCKFILE" fi + + ocf_log info "Starting service $ORACLE_SID completed successfully" return 0 } # # Stop Oracle # stop_oracle() { + ocf_log info "Stopping service $ORACLE_SID" + if ! [ -e "$ORACLE_HOME/bin/lsnrctl" ]; then - initlog -n $SCRIPT -q -s "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)" + ocf_log error "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)" + # XXX should this return 1? return 0 fi - initlog -n $SCRIPT -q -s "Stopping Oracle Database" - stop_db || return 1 + stop_db || stop_db abort + if [ $? -ne 0 ]; then + ocf_log error "Unable to stop DB for $ORACLE_SID" + return 1 + fi - - for LISTENER in ${LISTENERS}; do - initlog -n $SCRIPT -q -s "Stopping Oracle Listener $LISTENER" - lsnrctl stop $LISTENER - done + for LISTENER in ${LISTENERS}; do + ocf_log info "Stopping listener $LISTENER for $ORACLE_SID" + lsnrctl_stdout=$(lsnrctl stop "$LISTENER") + rv=$? + if [ $? -ne 0 ]; then + ocf_log error "Listener $LISTENER stop failed for $ORACLE_SID: $rv output $lsnrctl_stdout" + # XXX - failure? + fi + done - initlog -n $SCRIPT -q -s "Waiting for all Oracle processes to exit" - exit_idle + exit_idle if [ $? -ne 0 ]; then - initlog -n $SCRIPT -q -s "WARNING: Not all Oracle processes exited cleanly" + ocf_log error "WARNING: Not all Oracle processes exited cleanly for $ORACLE_SID" + # XXX - failure? fi if [ -n "$LOCKFILE" ]; then - rm -f $LOCKFILE + rm -f "$LOCKFILE" fi + + ocf_log info "Stopping service $ORACLE_SID succeeded" return 0 } # # Find and display the status of iAS infrastructure. # # This has three parts: # (1) Oracle database itself # (2) Oracle listener process # (3) OPMN and OPMN-managed processes # # - If all are (cleanly) down, we return 3. In order for this to happen, # $LOCKFILE must not exist. In this case, we try and restart certain parts # of the service - as this may be running in a clustered environment. # # - If some but not all are running (and, if $LOCKFILE exists, we could not # restart the failed portions), we return 1 (ERROR) # # - If all are running, return 0. In the "all-running" case, we recreate # $LOCKFILE if it does not exist. # status_oracle() { declare -i subsys_lock=1 declare -i last declare -i depth=$1 + ocf_log debug "Checking status for $ORACLE_SID depth $depth" + # Check for lock file. Crude and rudimentary, but it works - if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then + if [ -z "$LOCKFILE" ] || [ -f "$LOCKFILE" ]; then subsys_lock=0 fi # Check database status get_db_status $subsys_lock $depth update_status $? # Start last=$? # Check & report listener status - for LISTENER in ${LISTENERS}; do - get_lsnr_status $subsys_lock $depth $LISTENER - update_status $? $last - last=$? - done + for LISTENER in ${LISTENERS}; do + get_lsnr_status $subsys_lock $depth "$LISTENER" + update_status $? $last + last=$? + done # No lock file, but everything's running. Put the lock # file back. XXX - this kosher? if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then - touch $LOCKFILE + touch "$LOCKFILE" fi + ocf_log debug "Status returning $last for $ORACLE_SID" return $last } ######################## # Do some real work... # ######################## case $1 in - meta-data) - cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` - exit 0 - ;; + meta-data) + cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` + exit 0 + ;; start) - validation_checks $* + validation_checks $* start_oracle exit $? ;; stop) - validation_checks $* + validation_checks $* stop_oracle exit $? ;; status|monitor) - validation_checks $* + validation_checks $* status_oracle $OCF_CHECK_LEVEL exit $? ;; restart) $0 stop || exit $? $0 start || exit $? exit 0 ;; *) echo "usage: $SCRIPT {start|stop|restart|status|monitor|meta-data}" exit 1 ;; esac exit 0 diff --git a/rgmanager/src/resources/oralistener.sh b/rgmanager/src/resources/oralistener.sh index 2dd0f1d97..30b8e069e 100755 --- a/rgmanager/src/resources/oralistener.sh +++ b/rgmanager/src/resources/oralistener.sh @@ -1,170 +1,190 @@ #!/bin/bash # -# $Id: oralistener.sh 127 2009-08-21 09:17:52Z hevirtan $ -# # Red Hat Cluster Suite resource agent for controlling Oracle 10g # listener instances. This script will start, stop and monitor running # listeners. # # start: Will start given listener instance # # stop: Will stop given listener instance # # monitor: Will check that the listener is OK by calling lsnrctl status # # # Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved. -# Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. +# Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. # # 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. # # Grab the global RHCS helper functions . $(dirname $0)/ocf-shellfuncs . $(dirname $0)/utils/config-utils.sh . $(dirname $0)/utils/messages.sh . $(dirname $0)/utils/ra-skelet.sh declare -i RESTART_RETRIES=3 ORACLE_USER=$OCF_RESKEY_user ORACLE_HOME=$OCF_RESKEY_home LISTENER=$OCF_RESKEY_name LC_ALL=C LANG=C -PATH=/bin:/sbin:/usr/bin:/usr/sbin:$ORACLE_HOME/bin -export LC_ALL LANG PATH ORACLE_HOME +PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin +export LC_ALL LANG PATH ORACLE_USER ORACLE_HOME + +# clulog will not log messages when run by the oracle user. +# This is a hack to work around that. +if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then + ocf_log() { + prio=$1 + shift + logger -i -p daemon."$prio" -- "$*" + } +fi verify_all() { - clog_service_verify $CLOG_INIT - - if [ -z "$OCF_RESKEY_name" ]; then - clog_service_verify $CLOG_FAILED "Invalid name of service (listener name)" - return $OCF_ERR_ARGS - fi - - if [ -z "$OCF_RESKEY_home" ]; then - clog_service_verify $CLOG_FAILED "No Oracle home specified." - return $OCF_ERR_ARGS - fi - - if [ -z "$OCF_RESKEY_user" ]; then - clog_service_verify $CLOG_FAILED "No Oracle username specified." - return $OCF_ERR_ARGS - fi - - # Make sure the lsnrctl binary is in our $PATH - if [ ! -x $(which lsnrctl) ]; then - clog_service_verify $CLOG_FAILED "oralistener:${OCF_RESKEY_home}: Unable to locate lsnrctl command from path! ($PATH)" - return $OCF_ERR_GENERIC - fi - - clog_service_verify $CLOG_SUCCEED - return 0 -} + ocf_log debug "Validating configuration for $LISTENER" + + if [ -z "$OCF_RESKEY_name" ]; then + ocf_log error "Validation for $LISTENER failed: Invalid name of service (listener name)" + return $OCF_ERR_ARGS + fi + + if [ -z "$OCF_RESKEY_home" ]; then + ocf_log error "Validation for $LISTENER failed: No Oracle home specified." + return $OCF_ERR_ARGS + fi + + if [ -z "$OCF_RESKEY_user" ]; then + ocf_log error "Validation for $LISTENER failed: No Oracle username specified." + return $OCF_ERR_ARGS + fi + + # Super user? Automatically change UID and exec as oracle user. + # Oracle needs to be run as the Oracle user, not root! + if [ "`id -u`" = "0" ]; then + su $OCF_RESKEY_user -c "$0 $*" + exit $? + fi -start () { - clog_service_start $CLOG_INIT - - logfile="/tmp/oracle_lsn.$$" - su -p - $ORACLE_USER -c "lsnrctl start $LISTENER > $logfile" + # Make sure the lsnrctl binary is in our $PATH + if [ ! -x $(which lsnrctl) ]; then + ocf_log error "Validation for $LISTENER failed: Unable to locate lsnrctl command from path! ($PATH)" + return $OCF_ERR_GENERIC + fi - initlog -q -c "cat $logfile" - rm -f $logfile + ocf_log debug "Validation checks for $LISTENER succeeded" + return 0 +} + +start() { + ocf_log info "Starting listener $LISTENER" + lsnrctl_stdout=$(lsnrctl start "$LISTENER") + if [ $? -ne 0 ]; then + ocf_log error "start listener $LISTENER failed $lsnrctl_stdout" + return $OCF_ERR_GENERIC + fi - clog_service_start $CLOG_SUCCEED - return 0 + ocf_log info "Listener $LISTENER started successfully" + return 0 } -stop () { - clog_service_stop $CLOG_INIT - - logfile="/tmp/oracle_lsn.$$" - su -p - $ORACLE_USER -c "lsnrctl stop $LISTENER > $logfile" +stop() { + ocf_log info "Stopping listener $LISTENER" - initlog -q -c "cat $logfile" - rm -f $logfile + lsnrctl_stdout=$(lsnrctl stop "$LISTENER") + if [ $? -ne 0 ]; then + ocf_log debug "stop listener $LISTENER failed $lsnrctl_stdout" + return $OCF_ERR_GENERIC + fi - clog_service_stop $CLOG_SUCCEED - return 0 + ocf_log info "Listener $LISTENER stopped successfully" + return 0 } -monitor () { - clog_service_status $CLOG_INIT - - su -p - $ORACLE_USER -c "lsnrctl status $LISTENER" - rv=$? - if [ $rv == 0 ]; then - clog_service_status $CLOG_SUCCEED - return 0 # Listener is running fine - else - clog_service_status $CLOG_FAILED - return $OCF_ERR_GENERIC - fi +monitor() { + declare -i depth=$1 + + ocf_log debug "Checking status for listener $LISTENER depth $depth" + lsnrctl status "$LISTENER" >& /dev/null + if [ $? -ne 0 ]; then + ocf_log error "Listener $LISTENER not running" + return $OCF_ERR_GENERIC + fi + + ocf_log debug "Listener $LISTENER is up" + return 0 # Listener is running fine } recover() { + ocf_log debug "Recovering listener $LISTENER" + for (( i=$RESTART_RETRIES ; i; i-- )); do start - if [ $? == 0 ] ; then - break + if [ $? -eq 0 ] ; then + ocf_log debug "Restarted listener $LISTENER successfully" + break fi done if [ $i -eq 0 ]; then # stop/start's failed - return 1 (failure) + ocf_log debug "Failed to restart listener $LISTENER after $RESTART_RETRIES tries" return 1 fi - status - if [ $? != 0 ] ; then + status + if [ $? -ne 0 ] ; then + ocf_log debug "Failed to restart listener $LISTENER" return 1 # Problem restarting the Listener fi + ocf_log debug "Restarted listener $LISTENER successfully" return 0 # Success restarting the Listener } case $1 in - meta-data) - cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` - exit 0 - ;; - verify-all) - verify_all - exit $? - ;; - start) - verify_all && start - exit $? - ;; - stop) - verify_all && stop - exit $? - ;; - recover) - verify_all && recover - exit $? - ;; - status|monitor) - verify_all - monitor - exit $? - ;; - *) - echo "Usage: $0 {start|stop|recover|monitor|status|meta-data|verify-all}" - exit $OCF_ERR_GENERIC - ;; + meta-data) + cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` + exit 0 + ;; + verify-all) + verify_all $* + exit $? + ;; + start) + verify_all $* && start + exit $? + ;; + stop) + verify_all $* && stop + exit $? + ;; + recover) + verify_all $* && recover + exit $? + ;; + status|monitor) + verify_all $* + monitor $OCF_CHECK_LEVEL + exit $? + ;; + *) + echo "Usage: $0 {start|stop|recover|monitor|status|meta-data|verify-all}" + exit $OCF_ERR_GENERIC + ;; esac diff --git a/rgmanager/src/resources/svclib_nfslock b/rgmanager/src/resources/svclib_nfslock index 94cc0bec1..bc06269d5 100644 --- a/rgmanager/src/resources/svclib_nfslock +++ b/rgmanager/src/resources/svclib_nfslock @@ -1,281 +1,281 @@ #!/bin/bash # # Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved. # Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. # # 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. # # Do reclaim-broadcasts when we kill lockd during shutdown/startup # of a cluster service. # # Exported functions: # # notify_list_store # notify_list_merge # notify_list_broadcast # # # Usage: # statd_notify # # Copy out a list from , merge them with the system nfs lock # list, and send them out as after generating a random # state (needed so clients will reclaim their locks) # nfslock_statd_notify() { declare tmpdir declare nl_dir=$1 declare nl_ip=$2 declare command # Work around bugs in rpc.statd declare pid_xxx # Work around bugs in rpc.statd declare owner [ -z "$lockd_pid" ] && return 0 if ! [ -d $nl_dir ]; then return 0 fi if [ -z "`ls $nl_dir/sm/* 2> /dev/null`" ]; then ocf_log debug "No hosts to notify" return 0 fi tmpdir=$(mktemp -d /tmp/statd-$2.XXXXXX) # Ok, copy the HA directory to something we can use. mkdir -p $tmpdir/sm # Copy in our specified entries cp -f $nl_dir/sm/* $tmpdir/sm # Copy in our global entries # XXX This might be what we just copied. if [ -d "/var/lib/nfs/statd/sm" ]; then owner=$(ls -dl /var/lib/nfs/statd/sm | awk '{print $3"."$4}') cp -f /var/lib/nfs/statd/sm/* $tmpdir/sm elif [ -d "/var/lib/nfs/sm" ]; then owner=$(ls -dl /var/lib/nfs/statd/sm | awk '{print $3"."$4}') cp -f /var/lib/nfs/sm/* $tmpdir/sm fi # # Generate a random state file. If this ends up being what a client # already has in its list, that's bad, but the chances of this # are small - and relocations should be rare. # dd if=/dev/urandom of=$tmpdir/state bs=1 count=4 &> /dev/null # # Make sure we set permissions, or statd will not like it. # chown -R $owner $tmpdir # # Tell rpc.statd to notify clients. Don't go into background, # because statd is buggy and won't exit like it's supposed to after # sending the notifications out. # ocf_log info "Sending reclaim notifications via $nl_ip" command="rpc.statd -NFP $tmpdir -n $nl_ip" eval $command 2>&1 & sleep 3 # XXX - the instance of rpc.statd we just spawned is supposed # to exit after it finishes notifying clients. # rpc.statd spawned which is still running handles the actual # new SM_MON requests... we hope 3 seconds is enough time # to get all the SM_NOTIFY messages out. rpc.statd = bugged # # clean up # pid_xxx=`ps auwwx | grep "$command" | grep -v grep | awk '{print $2}'` kill $pid_xxx rm -rf $tmpdir return 0 } # # Copy of isSlave from svclib_ip and/or ip.sh # nfslock_isSlave() { declare intf=$1 declare line if [ -z "$intf" ]; then ocf_log err "usage: isSlave " return 1 fi line=$(/sbin/ip link list dev $intf) if [ $? -ne 0 ]; then ocf_log err "$intf not found" return 1 fi if [ "$line" = "${line/<*SLAVE*>/}" ]; then return 2 fi # Yes, it is a slave device. Ignore. return 0 } # # Get all the IPs on the system except loopback IPs # nfslock_ip_address_list() { declare idx dev family ifaddr while read idx dev family ifaddr; do if [ "$family" != "inet" ] && [ "$family" != "inet6" ]; then continue fi if [ "$dev" = "lo" ]; then # Ignore loopback continue fi nfslock_isSlave $dev if [ $? -ne 2 ]; then continue fi idx=${idx/:/} echo $dev $family ${ifaddr/\/*/} ${ifaddr/*\//} done < <(/sbin/ip -o addr list | awk '{print $1,$2,$3,$4}') return 0 } # # Usage: broadcast_notify # # Send the contents of out via all IPs on the system. # notify_list_broadcast() { declare dev family addr maskbits ip_name declare lockd_pid=$(pidof lockd) declare nl_dir=$1 # First of all, send lockd a SIGKILL. We hope nfsd is running. # If it is, this will cause lockd to reset the grace period for # lock reclaiming. if [ -n "$lockd_pid" ]; then ocf_log info "Asking lockd to drop locks (pid $lockd_pid)" kill -9 $lockd_pid else ocf_log warning "lockd not running; cannot notify clients" return 1 fi while read dev family addr maskbits; do if [ "$family" != "inet" ]; then continue fi ip_name=$(clufindhostname -i $addr) if [ -z "$ip_name" ]; then nfslock_statd_notify $nl_dir $addr else nfslock_statd_notify $nl_dir $ip_name fi done < <(nfslock_ip_address_list) } # # Store the lock monitor list from rpc.statd - do this during a teardown # after the IP addresses of a service have been taken offline. Note that # this should be done by HA-callout programs, but this feature is not in # RHEL3. # notify_list_store() { declare nl_dir=$1 declare owner mkdir -p $nl_dir/sm if [ -d "/var/lib/nfs/statd/sm" ]; then if [ -z "`ls /var/lib/nfs/statd/sm/* 2> /dev/null`" ]; then return 1 # nothing to do! fi owner=$(ls -dl /var/lib/nfs/statd/sm | awk '{print $3"."$4}') - cp -af /var/lib/nfs/statd/sm/* $nl_dir/sm + cp -Rdpf /var/lib/nfs/statd/sm/* $nl_dir/sm chown -R $owner $nl_dir return 0 elif [ -d "/var/lib/nfs/sm" ]; then if [ -z "`ls /var/lib/nfs/sm/* 2> /dev/null`" ]; then return 1 # nothing to do! fi owner=$(ls -dl /var/lib/nfs/sm | awk '{print $3"."$4}') - cp -af /var/lib/nfs/sm/* $nl_dir/sm + cp -Rdpf /var/lib/nfs/sm/* $nl_dir/sm chown -R $owner $nl_dir return 0 fi return 1 } # # Merge the contents of /sm with the system-wide list # Make sure ownership is right, or statd will hiccup. This should not # actually ever be needed because statd will, upon getting a SM_MON # request, create all the entries in this list. It's mostly for # housekeeping for next time we relocate the service. # notify_list_merge() { declare nl_dir=$1 declare owner if [ -z "`ls $nl_dir/* 2> /dev/null`" ]; then return 1 fi if [ -d "/var/lib/nfs/statd/sm" ]; then owner=$(ls -dl /var/lib/nfs/statd/sm | awk '{print $3"."$4}') - cp -af $nl_dir/sm/* /var/lib/nfs/statd/sm + cp -Rdpf $nl_dir/sm/* /var/lib/nfs/statd/sm chown -R $owner $nl_dir return 0 elif [ -d "/var/lib/nfs/sm" ]; then owner=$(ls -dl /var/lib/nfs/sm | awk '{print $3"."$4}') - cp -af $nl_dir/sm/* /var/lib/nfs/sm + cp -Rdpf $nl_dir/sm/* /var/lib/nfs/sm chown -R $owner $nl_dir return 0 fi return 1 }