#!/bin/bash
#
# Run-level Startup script for the Oracle Restart
#
# $Id$
#

### BEGIN INIT INFO
# Provides:          oracle-restart
# Required-Start:    $local_fs time network 
# Required-Stop:     $null
# X-Start-Before:    oracle-asm oracle-listener
# X-Stop-After:      oracle-asm oracle-listener
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Oracle Restart services
# Description:       Start Oracle Restart services,
#                    standalone Grid Infrastructure.
### END INIT INFO

# chkconfig: 345 80 50
# description: Startup/Shutdown Oracle Restart
#
# Usage:
#          start | stop | status

source /lib/lsb/oracle-restart-functions

SLOGFILE=/var/log/oracle/oraclelog
ORA_OWNER="oracle"
rc=$ORACLE_OKAY

export ORA_OWNER

echo >> $SLOGFILE
echo "I: $0: `date '+%F %T'`: Run command $* " >> $SLOGFILE

oracle_restart_usage() {
    cat << __EOFF__
 Usage: 
   $0 start | stop | status
 
 Control Oracle Retsart services.

 Arguments:
   start  - Start Oracle Restart services and resources
   stop   - Stop Oracle Restart services and resources
   status - Show status of Oracle Restart services and resources
__EOFF__
}


case "$1" in
    start)
       echo -n "Start Oracle Restart service: " | tee -a $SLOGFILE
       oracle_restart_start >> $SLOGFILE 2>&1
       case ${PIPESTATUS[0]} in
            $ORACLE_OKAY ) str="OK" ;;
            $ORACLE_PASS ) str="PASS" ;;
            * ) str="Error"; rc=$((10+rc+1)) ;;
        esac
        echo " $str" | tee -a $SLOGFILE
    ;;
    stop)
       echo -n "Stop Oracle Restart service: " | tee -a $SLOGFILE
       oracle_restart_stop >> $SLOGFILE 2>&1
       case ${PIPESTATUS[0]} in
            $ORACLE_OKAY ) str="OK" ;;
            $ORACLE_PASS ) str="PASS" ;;
            * ) str="Error"; rc=$((10+rc+1)) ;;
        esac
        echo " $str" | tee -a $SLOGFILE
     ;;
    status)
       echo -n "Status of Oracle Restart service: " | tee -a $SLOGFILE
       oracle_restart_status 2>&1 | tee -a $SLOGFILE
       case ${PIPESTATUS[0]} in
            $ORACLE_OKAY ) str="OK" ;;
            $ORACLE_PASS ) str="PASS" ;;
            * ) str="Error"; rc=$((10+rc+1)) ;;
        esac
        echo " $str" | tee -a $SLOGFILE
     ;;
    help)
        oracle_restart_usage
    ;;
    *)
        oracle_restart_usage
        rc=$ORACLE_ERROR
esac

echo >> $SLOGFILE

exit $rc

