Oracle HA 脚本
[bash toolbar="false"]#!/bin/bash
#
# /etc/init.d/dbora
# chkconfig: 2345 02 98
# description: Oracle is meant to run under Linux Oracle Server
#
# Source function library.
. /etc/rc.d/init.d/functions
ORACLE_HOME=/oracle/product/10.2.0/db_1
ORACLE_SID=hatest
ORACLE_NAME=oracle
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
#
# 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
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”)
>> $logfile 2>&1) || return 1
#return $?
if [ -n "$LOCKFILE" ]; then
touch $LOCKFILE
fi
#/usr/local/tomcat/bin/catalina.sh start
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
[/bash]
相关日志:
- 2012年05月11日 -- 了解 Oracle Ksplice (0)
- 2011年12月26日 -- Liferay Portal 集群配置指南 (0)
- 2011年10月16日 -- 在 RHEL 5.5 下应用 RHCS 实现 Oracle HA (0)
- 2011年09月6日 -- 如何在 Linux 下完全卸载 Oracle 10g ? (0)
- 2011年08月25日 -- 在 RHEL 5.5 下安装 Oracle RAC (0)
- 2011年05月18日 -- RMAN 整库备份异机恢复流程 (0)
Categories
- 信息世界 | IT (95)
- Certification (1)
- Cloud Computing (1)
- Database (16)
- Google (10)
- Hardware (2)
- J2EE (4)
- Network (19)
- OS (18)
- Programming (11)
- Virtualization (1)
- Webmaster (11)
- 数码先锋 | Digital (17)
- 时事评论 | Event (5)
- 时光飞驰 | News (2)
- 杂七杂八 | Mix (2)
- 流金岁月 | Life (8)
- 游戏志 | Game (13)
- 看电影 | Movie (10)
- 红魔拥趸 | ManUtd (5)
- 读书频道 | Reading (1)
- 音乐无限 | Music (4)
- 信息世界 | IT (95)
Twitter
- I'm at 大连国美电器胜利新活馆 (大连市, 辽宁省) http://t.co/f7pxcNfg 17 小时前
- I'm at Xinghai Square | 星海广场 (Dalian, China) http://t.co/gKNqq2qV 23 小时前
- I'm at 壹品星海 (Dalian, China) http://t.co/o7SCCIrG 23 小时前
- 晚上和以前的同事喝了点酒,准备睡觉了,希望明天能把公司的电脑修好,没有电脑办公还真不方便,不知道明天印度那边有没有培训的消息。 2012-05-16
- 非常值得读的一本书! http://t.co/lV8ulDnV 2012-05-16
- I'm at 大连软件园15号楼 (大连市, 辽宁省) http://t.co/03DYYUKY 2012-05-16
- @yamiugly 好奇你做的是什么工作? 2012-05-16
- I'm at 壹品星海 (Dalian, China) http://t.co/frkQvlIn 2012-05-15
- I just ousted @fndhrt as the mayor of 大连软件园15号楼 on @foursquare! http://t.co/yn7fSLY6 2012-05-15
- I'm at 大连软件园15号楼 (大连市, 辽宁省) http://t.co/KH2m2Z4R 2012-05-15
- @terrysosi_chan 小日子过的太充实了! 2012-05-15
- RT @GossipSama: 玩diablo 2的时候我23岁,玩diablo 3的时候我34岁。暴雪是要等我不再2了才出3是么?那是不是要45岁才玩到4? 2012-05-15
- I'm at 中山广场 Zhongshan Circus (大连, 中国) http://t.co/fiD6vqHS 2012-05-14
- 英超还真他妈的好看。昨晚90分钟的比赛,跟坐过山车一样,如果不看直播,是体会不到这种刺激的,呵呵,英超第20年,今年的冠军真的很有戏剧性,恭喜曼城,明年的曼联面对的局势更难,曼城还会加大投入的,看看曼城现在的阵容,明年再买几个强援,大耳朵杯指日可待! 2012-05-14
- @Fatal1tyV 怎么弄? 2012-05-14
Latest Comments
Foursquare Checkins
标签




