#!/bin/sh # # Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. # # afd.sbs - init script for the ASM Filter Driver # This is run by the RC system. ################### INSTANTIATED VARIABLES #################### ORACLE_HOME=%ORA_CRS_HOME% export ORACLE_HOME PATH=/usr/bin:/bin:$ORACLE_HOME/bin USER=%ORACLE_OWNER% GROUP=%ORA_ASM_GROUP% ################### TOOLS ##################################### UNAME=/bin/uname PLATFORM=`$UNAME` AFDROOT=${ORACLE_HOME}/bin/afdroot AFDLOAD=${ORACLE_HOME}/bin/afdload AFDBOOT=${ORACLE_HOME}/bin/afdboot AFDTOOL=${ORACLE_HOME}/bin/afdtool ######### CLI tools ######### ECHO=/bin/echo SED=/bin/sed SLEEP=/bin/sleep RMF="/bin/rm -f" TOUCH=/bin/touch SU=/bin/su LOGMSG="/bin/logger -puser.err" LOGERR="/bin/logger -puser.alert" CHMOD=/usr/bin/chmod MKDIR=/usr/bin/mkdir CHOWN=/usr/bin/chown GREP=/bin/grep AFD_PORTAL_DEV=/dev/oracleafd/admin ORACLEASM_INIT=/etc/init.d/oracleasm ORACLEASM_CONFIG=/etc/sysconfig/oracleasm # How long to wait (in seconds) before rechecking a dependency, # and printing out messages about it. DEP_CHECK_WAIT=60 case $PLATFORM in Linux) LOGGER="/usr/bin/logger" if [ ! -f "$LOGGER" ]; then LOGGER="/bin/logger" fi LOGERR="$LOGGER -puser.err" LOGMSG="$LOGGER -puser.alert" SUBSYSFILE="/var/lock/subsys/afd" CHMOD=/bin/chmod MKDIR=/bin/mkdir CHOWN=/bin/chown DRIVERLOADCMD=/sbin/modprobe AFD_PORTAL_DEV_DISKS=/dev/oracleafd/disks $SU -l $USER -c "$ECHO \$TZ > /tmp/oratz.$$ " > /dev/null 2>&1 NEWTZ=`$SED 's/^[ \t]*//;s/[ \t]*$//' < /tmp/oratz.$$` $RMF /tmp/oratz.$$ if [ ! -z "$NEWTZ" ]; then TZ=$NEWTZ; export TZ; fi ;; SunOS) DRIVERLOADCMD="/usr/sbin/modload -p" # Revisit this code if /var gets mounted after we create this dir AFD_PORTAL_DEV_DISKS=/var/opt/oracle/oracleafd/disks $SU - $USER -c "$ECHO \$TZ > /tmp/oratz.$$ " > /dev/null 2>&1 NEWTZ=`$SED 's/^[ \t]*//;s/[ \t]*$//' < /tmp/oratz.$$` $RMF /tmp/oratz.$$ if [ ! -z "$NEWTZ" ]; then TZ=$NEWTZ; export TZ; fi ;; *) /bin/echo "ERROR: Unknown Operating System" exit -1 ;; esac # Function : Log message to syslog and console log_console () { $ECHO "$*" $LOGMSG "$*" } log_error () { $ECHO "$*" $LOGERR "$*" } success_status() { $LOGMSG "OK" return 0 } if_fail() { RC="$1" REASON="$2" if [ "$RC" = "0" ] then success_status return fi log_error "${REASON}" exit 1 } add_subsysfile() { case $PLATFORM in Linux) # Create /var/lock/subsys/afd $TOUCH $SUBSYSFILE ;; *) ;; esac } rem_subsysfile() { case $PLATFORM in Linux) # remove /var/lock/subsys/afd $RMF $SUBSYSFILE ;; *) ;; esac } afd_scandisk() { if [ ! -r $AFDBOOT ] then CMD="/sbin/afdboot -scandisk" else CMD="$AFDBOOT -scandisk" fi $LOGMSG "Discovering AFD disks ($CMD)" # Run the command as root to see all devices $CMD if [ "$?" != "0" ] then $LOGMSG "Failed to scan AFD devices" else $LOGMSG "AFD scandisk done." fi } afd_loaddriver() { load_works=true # If GIHOME containing afdload is not available, # we just run 'modprobe oracleafd' to load. if [ ! -r $AFDLOAD ] then CMD="$DRIVERLOADCMD oracleafd" else CMD="${AFDLOAD} start" fi $LOGMSG "Loading AFD ($CMD)" $CMD if_fail "$?" "Failed to Load AFD" # wait for portal device to be available ... for check in 10 9 8 7 6 5 4 3 2 1 do if [ ! -r $AFD_PORTAL_DEV ] then load_works=false $SLEEP 2 else load_works=true break fi done if [ $load_works = false ]; then $LOGMSG "INFO (Oracle AFD):: failed to detect control device." else $LOGMSG "AFD Loaded." fi } afd_enablelog() { $LOGMSG "Enable AFD Kernel Logging... " fs_present=true # wait for afdtool to be available ... for check in 10 9 8 7 6 5 4 3 2 1 do if [ ! -r $AFDTOOL ] then fs_present=false $SLEEP 10 else fs_present=true break fi done if [ $fs_present = true ] then CMD="$AFDTOOL -log -d" $CMD if [ "$?" != "0" ] then $LOGMSG "Failed to enable AFD Kernel Logging" else $LOGMSG "AFD kernel Logging enabled" fi else $LOGMSG "INFO (Oracle AFD):: unable to enable AFD Kernel Logging" fi } install() { $LOGMSG "Installing AFD... " CMD="${AFDROOT} install" $CMD if_fail "$?" "Failed to install AFD" add_subsysfile $LOGMSG "AFD Installed." # Discover the afd disks afd_scandisk } uninstall() { $LOGMSG "Uninstalling AFD... " CMD="${AFDROOT} uninstall" $CMD if_fail "$?" "Failed to uninstall AFD" rem_subsysfile $LOGMSG "AFD Uninstalled." } disable_asmlib() { if [ -r $ORACLEASM_INIT ] then $LOGMSG "ASMFD disabling oracleasm ... " CMD="$ORACLEASM_INIT disable" $CMD $LOGMSG "'$CMD' executed." fi # Assert oracleasm is disabled if [ -r $ORACLEASM_CONFIG ] then CMD="$GREP -i ORACLEASM_ENABLED=true $ORACLEASM_CONFIG" OUTPUT=`$CMD` if [ "$?" = "0" ] then $LOGMSG "ORACLEASM_ENABLED is set to true in $ORACLEASM_CONFIG. ASMFD can't proceed." exit 1 fi fi } start_afd() { $LOGMSG "Starting AFD... " works=true if [ ! -r $AFDLOAD ] then works=false fi if [ $works = false ] then $LOGMSG "INFO (Oracle AFD) :: Filesystem containing $AFDLOAD is not available." $LOGMSG "INFO (Oracle AFD) :: Using a fallback option." fi # Attempt to stop oracleasm on Linux if [ $PLATFORM = "Linux" ] then disable_asmlib fi # load AFD driver afd_loaddriver add_subsysfile # create /dev/oracleafd/disks & set permissions $MKDIR -p $AFD_PORTAL_DEV_DISKS $CHMOD 0770 $AFD_PORTAL_DEV_DISKS $CHOWN $USER:$GROUP $AFD_PORTAL_DEV_DISKS # Discover the afd disks afd_scandisk # Set permissions on files under AFD_PORTAL_DEV_DISKS (after scan) $CHOWN $USER:$GROUP $AFD_PORTAL_DEV_DISKS/* # Enable AFD Kernel logging if not done # If file system was available, 'afdload' starts logging # Check again and attempt to enable kernel logging if [ $works = false ] then afd_enablelog fi } stop_afd() { $LOGMSG "Stoping AFD... " CMD="${AFDLOAD} stop" $CMD if_fail "$?" "Failed to stop AFD" rem_subsysfile $LOGMSG "AFD Unloaded." } status() { $LOGMSG "Checking AFD status..." CMD="${AFDLOAD} check" $CMD if_fail "$?" "AFD Portal device is not accessible" $LOGMSG "AFD Accessible" } # Main loop case $1 in 'start'|'run') start_afd ;; 'stop') stop_afd ;; 'restart') stop_afd start_afd ;; 'status') status ;; 'install') install ;; 'uninstall') uninstall ;; 'enable') $LOGMSG "Start AFD.." start_afd ;; 'disable') $LOGMSG "Stop AFD.." stop_afd ;; *) $ECHO "Usage: $0 {stop|start|run|restart|status|install|uninstall|disable|enable}" exit 1; ;; esac exit 0