linux oracle配置文档

#!/bin/bash  
# /etc/init.d/dbora  
# chkconfig: 2345 02 98  
# description: oracle is meant to run under Linux Oracle Server  
#. /etc/rc.d/init.d/functions   
ORACLE_HOME=/u01/app/oracle/product/10g/  
ORACLE_SID=ORCL
ORACLE_NAME=orcl
LOCKFILE="$ORACLE_HOME/.oracle.lock"
RESTART_RETRIES=3
DB_PROCNAMES="pmon"
LSNR_PROCNAME="tnslsnr"  
#RETVAL=0
#Start the oracle Server   
#The following command assumes that the oracle login will not prompt the password  
start() {
  echo  "Starting Oracle10g Server... "          
  tmpfile=/home/oracle/'basename $0'-start.$$
  logfile=/home/oracle/'basename $0'-start.log
  echo "startup" > $tmpfile          
  echo "quit" >> $tmpfile           
  su - $ORACLE_NAME -c "sqlplus \"/ as sysdba\" < $tmpfile &> $logfile"          
  if [ $? -ne 0 ]; then                  
          echo "ORACLE_HOME Incorrectly set?"
          echo "See $logfile for more information."
          return 1          
  fi           
  # If we see:          
  # ORA-.....: failure, we failed          
  rm -f $tmpfile          
  grep -q "failure" $logfile          
  if [ $? -eq 0 ]; then                  
      rm -f $tmpfile                  
      echo "ORACLE_SID Incorrectly set?"
      echo "See $logfile for more information."
      return 1          
  fi            
  echo "Starting listern..."           
  ((su - $ORACLE_NAME -c "$ORACLE_HOME/bin/lsnrctl start listener") >> $logfile   2>&1) || return 1
  #return $?          
  if [ -n "$LOCKFILE" ];then                  
      touch $LOCKFILE          
  fi  
  return 0  
}   
           
stop() {
  echo "Shutting down Oracle10g Server..."  
  declare tmpfile          
  declare logfile           
  tmpfile=/home/oracle/`basename $0`-stop.$$  
  logfile=/home/oracle/`basename $0`-stop.log
 
  if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
          echo           
      else            
          echo "oracle is not run"            
      return 0          
  fi           
  # Setup for Stop ...          
  echo "shutdown abort" > $tmpfile          
  echo "quit" >> $tmpfile           

  su - $ORACLE_NAME -c "sqlplus \"/ as sysdba\" < $tmpfile &> $logfile"
    if [ $? -ne 0 ];then                  
    echo "ORACLE_HOME Incorrectly set?"
    echo "See $logfile for more information."
      return 1          
  fi           
      #           
      # If we see 'failure' in the log, we're done.  
      rm -f $tmpfile          
      grep -q failure $logfile          
      if [ $? -eq 0 ]; then                  
          echo                  
          echo "Possible reason: ORACLE_SID Incorrectly set."                  
          echo "See $logfile for more information."
      return 1          
  fi           
               
  status $LSNR_PROCNAME          
      if [ $? -ne 0 ] ;then            
          if [ -n "$LOCKFILE" ];then               
           rm -f $LOCKFILE             
        fi               
      return 0
          # Listener is not running          
      fi          
  ((su - $ORACLE_NAME -c "$ORACLE_HOME/bin/lsnrctl stop") >> $logfile   2>&1) || return 1           
  if [ -n "$LOCKFILE" ];
      then               
      rm -f $LOCKFILE          
  fi          
  return 0  
}   
 
get_lsnr_status()  {          
  declare -i subsys_lock=$1           
  status $LSNR_PROCNAME          
  if [ $? == 0 ] ; then                  
      return 0
      # Listener is running fine          
  elif [ $subsys_lock -ne 0 ]; then
      return 3         
  elif [ $? -ne 0 ] ; then                 
      return 1          
  fi
}   
                   
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                  
      elif [ $subsys_lock -ne 0 ]; then
          return 3                 
      elif  [ $? -ne 0 ] ; then   

          return 1                  
      fi           
  done
}   
                       
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  
}  

status_ias()  
{          
    declare -i subsys_lock=1         
    declare -i last          
    # Check for lock file.Crude and rudimentary, but it works          
    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=$?           
    
    # Check & report opmn / opmn-managed process status          
    #get_opmn_status $subsys_lock          
    #update_status $? $last          
    #last=$?           #          
    # 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          
    fi          
    return $last  
    }   
    
restart() {
    echo -n "Restart Oracle10g Server"             
    stop               
    start  
    echo  
}   

case "$1" in  
        start)
          start      
          exit $?      
          ;;  
      stop)       
          stop
          exit $?  
          ;;  
      status)      
              status_ias      
              exit $?  
              ;;  
      restart|reload)      
              stop      
              start  
              ;;  
      *)  
          echo "Usage: $0 {start|stop|reload|restart|status}"  
          exit 1  
          ;;  
    esac  
    exit 0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值