#!/bin/sh # # Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. # # ohasd.sbs - Control script for the Oracle HA Services daemon # This script is invoked by the rc system. # # Note: # For security reason, all cli tools shipped with Clusterware should be # executed as HAS_USER in init.ohasd and ohasd rc script for SIHA. (See bug # 9216334 for more details) # ### BEGIN INIT INFO # Provides: oracle_has # Required-Start: $network $syslog $remote_fs # Should-Start: open_iscsi raw afd # Required-Stop: $network $syslog $remote_fs # Should-Stop: open_iscsi # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Description: Start and Stop Oracle High Availability Service ### END INIT INFO ######### Shell functions ######### # Function : Log message to syslog and console log_console () { $ECHO "$*" $LOGMSG "$*" } tolower_host() { #If the hostname is an IP address, let hostname #remain as IP address H1=`$HOSTN` len1=`$EXPRN "$H1" : '.*'` len2=`$EXPRN match $H1 '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'` # Strip off domain name in case /bin/hostname returns # FQDN hostname if [ $len1 != $len2 ]; then H1=`$ECHO $H1 | $CUT -d'.' -f1` fi $ECHO $H1 | $TR '[:upper:]' '[:lower:]' } # Invoke crsctl as root in case of clusterware, and HAS_USER in case of SIHA. # Note: Argument with space might be problemactic (my_crsctl 'hello world') my_crsctl() { if [ $HAS_USER = "root" ]; then $CRSCTL $* else $SU $HAS_USER -c "$CRSCTL $*" fi } ################################### ######### Instantiated Variables ######### ORA_CRS_HOME=%ORA_CRS_HOME% export ORA_CRS_HOME # Definitions HAS_USER=%HAS_USER% SCRBASE=%SCRBASE% PROG="ohasd" ########################################## #limits(fixed) CRS_LIMIT_CORE=%CRS_LIMIT_CORE% CRS_LIMIT_MEMLOCK=%CRS_LIMIT_MEMLOCK% ######### CLI tools ######### HOSTN=/bin/hostname ECHO=/bin/echo SLEEP=/bin/sleep BASENAME=/bin/basename RMF="/bin/rm -f" HOSTN=/bin/hostname TOUCH=/bin/touch SU=/bin/su EXPRN=/usr/bin/expr CUT=/usr/bin/cut CAT=/bin/cat GREPX="/bin/grep -x" LOGMSG="/bin/logger -puser.err" LOGERR="/bin/logger -puser.alert" MKDIR=/usr/bin/mkdir CHMOD=/usr/bin/chmod CHOWN=/usr/bin/chown DIRNAME=/usr/bin/dirname NAMEDPIPE=/var/tmp/.oracle/npohasd # Location to TR differs in diff. platforms. TR=/bin/tr #solaris on amd has issue with /bin/tr [ 'SunOS' = `/bin/uname` ] && TR=/usr/xpg4/bin/tr #on linux tr is at /usr/bin/tr [ 'Linux' = `/bin/uname` ] && TR=/usr/bin/tr CRSCTL=$ORA_CRS_HOME/bin/crsctl ############################# # How long to wait (in seconds) before rechecking a dependency, # and printing out messages about it. DEP_CHECK_WAIT=60 MY_HOST=`tolower_host` ENV_FILE="${ORA_CRS_HOME}/crs/install/s_crsconfig_${MY_HOST}_env.txt" PLATFORM=`/bin/uname` case $PLATFORM in Linux) LOGGER="/usr/bin/logger" if [ ! -f "$LOGGER" ];then LOGGER="/bin/logger" fi LOGMSG="$LOGGER -puser.err" LOGERR="$LOGGER -puser.alert" SUBSYSFILE="/var/lock/subsys/ohasd" MKDIR=/bin/mkdir CHMOD=/bin/chmod CHOWN=/bin/chown ;; HP-UX) NAMEDPIPE=/tmp/.oracle/npohasd ;; SunOS) ;; AIX) NAMEDPIPE=/tmp/.oracle/npohasd ;; OSF1) ;; *) $ECHO "ERROR: Unknown Operating System" exit -1 ;; esac #bug10327228 - To create .oracle directory if it does not exist NAMEDPIPE_DIR=`$DIRNAME $NAMEDPIPE` if [ ! -d $NAMEDPIPE_DIR ] then $MKDIR -p $NAMEDPIPE_DIR $CHMOD 01777 $NAMEDPIPE_DIR $CHOWN root $NAMEDPIPE_DIR fi start_stack() { # enable HA by default on most unix platforms case $PLATFORM in Linux) # touch /var/lock/subsys/ohasd so that the shutdown # scripts get called during shutdown time (refer bug 8740030) $TOUCH $SUBSYSFILE GIPCD_PASSTHROUGH=false export GIPCD_PASSTHROUGH ;; HP-UX) GIPCD_PASSTHROUGH=false export GIPCD_PASSTHROUGH ;; SunOS) GIPCD_PASSTHROUGH=false export GIPCD_PASSTHROUGH ;; AIX) GIPCD_PASSTHROUGH=false export GIPCD_PASSTHROUGH ;; OSF1) ;; esac $ECHO "Starting $PROG: " AUTOSTARTFILE=$SCRBASE/$MY_HOST/$HAS_USER/ohasdstr # Wait until it is safe to start CRS daemons. Wait for 10 minutes for # filesystem to mount (if crs is enabled). # Print message to syslog and console. crsenabled=false if [ -r $AUTOSTARTFILE ] then case `$CAT $AUTOSTARTFILE` in enable*) crsenabled=true log_console "" esac fi if $crsenabled then works=true for minutes in 10 9 8 7 6 5 4 3 2 1 do if [ ! -r $CRSCTL ] then works=false log_console "Waiting $minutes minutes for filesystem containing $CRSCTL." $SLEEP $DEP_CHECK_WAIT else works=true break fi done if [ ! $works ] then log_console "Fatal Error :: Timed out waiting for the filesystem containing $CRSCTL." log_console "Oracle Grid Infrastructure not able to access filesystem containing $CRSCTL." log_console "Fix the problem and issue command 'crsctl start has' as $HAS_USER user to start Oracle Grid Infrastructure." exit 1 fi else $LOGERR "Not waiting for filesystem containing $CRSCTL because Oracle HA daemon is not enabled." fi #source the script that has limit values . $ENV_FILE > /dev/null 2>&1 # see init.ohasd.sbs for a full rationale case $PLATFORM in Linux) # MEMLOCK limit is for Bug 9136459 ulimit -l $CRS_LIMIT_MEMLOCK ulimit -c $CRS_LIMIT_CORE ulimit -n $CRS_LIMIT_OPENFILE ulimit -u $CRS_LIMIT_NPROC ;; *) ulimit -c $CRS_LIMIT_CORE ulimit -n $CRS_LIMIT_OPENFILE if [ "$PLATFORM" = "AIX" ] then ulimit -u $CRS_LIMIT_NPROC fi ;; esac if [ -r $AUTOSTARTFILE ] then case `$CAT $AUTOSTARTFILE` in enable*) $LOGERR "Oracle HA daemon is enabled for autostart." my_crsctl start has -nowait ;; disable*) $LOGERR "Oracle HA daemon is disabled for autostart." ;; *) $LOGERR "Oracle HA daemon is disabled by damaged install." $LOGERR "Unexpected settings found in $AUTOSTARTFILE." ;; esac else # If the SCR directory does not exist, then either the user changed # their hostname, or they wiped sections of the disk. if [ ! -d "$SCRDIR" ] then $LOGERR "Oracle Cluster Ready Services startup disabled." $LOGERR "Could not access $AUTOSTARTFILE." else $LOGERR "Oracle Cluster Ready Services is disabled by damaged install." $LOGERR "Could not access $AUTOSTARTFILE." fi fi } stop_stack() { case $PLATFORM in Linux) # remove /var/lock/subsys/ohasd now that the shutdown # script has been called at shutdown time (refer bug 8740030) $RMF $SUBSYSFILE ;; *) ;; esac $ECHO "Stopping Oracle Clusterware stack" my_crsctl stop has -f -system } install_stack() { case $PLATFORM in Linux) # touch /var/lock/subsys/ohasd so that the shutdown # scripts get called during shutdown time (refer bug 8740030) $TOUCH $SUBSYSFILE ;; *) ;; esac } deinstall_stack() { case $PLATFORM in Linux) # remove /var/lock/subsys/ohasd now that the shutdown # script has been called at shutdown time (refer bug 8740030) $RMF $SUBSYSFILE ;; *) ;; esac } # See how we were called. case "$1" in deinstall) deinstall_stack ;; install) install_stack ;; start) start_stack ;; run) start_stack ;; stop) stop_stack ;; esac exit 0;