rhel as3下自動啟動和關閉oracle的指令碼

weifenghq發表於2007-06-04
在redhat系統關閉的過程中會檢查/var/lock/subsys下的檔案,逐一關閉每個服務,如果某一執行的服務在/var/lock/subsys下沒有相應的選項。在系統關閉的時候,會像殺死普通程式一樣殺死這個服務。

1 建立檔案/etc/init.d/oracle內容後。
2 使這一檔案可以執行 chmod a+x /etc/init.d/oracle
3 測試/etc/init.d/oracle start和/etc/init.d/oracle可以正常啟動和關閉資料庫
4 建立聯結
ln -s /etc/init.d/oracle /etc/rc3.d/S95oracle
ln -s /etc/init.d/oracle /etc/rc5.d/S95oracle
ln -s /etc/init.d/oracle /etc/rc0.d/K05oracle
ln -s /etc/init.d/oracle /etc/rc1.d/K05oracle
ln -s /etc/init.d/oracle /etc/rc2.d/K05oracle
ln -s /etc/init.d/oracle /etc/rc4.d/K05oracle
ln -s /etc/init.d/oracle /etc/rc6.d/K05oracle

這樣在系統啟動時將可以自動啟動資料庫,系統關閉時將自動關閉資料庫
可以透過資料庫的alert檔案確認。


##########start of /etc/init.d/oracle################
#!/bin/bash
#
# chkconfig: 35 95 5
# description: Startup/shutdown script for oracle listener
# and instance;
# tested in rhel as 3u3 with oracle 10gR1
# writen by blue_stone@xinhuanet.com
# 12/30/2005
case "$1" in
start)
#when system stop redhat check /var/lock/subsys/oracle
#to make sure oracle is running.
touch /var/lock/subsys/oracle
# start tsnlisnter
echo "start tsnlisnter"
su - oracle -c "lsnrctl start"

# start database
echo "Start Oracle database instance"
su - oracle -c "echo "
CONN / AS SYSDBA
STARTUP
exit "|sqlplus /NOLOG"

# start enterprise manager
#echo " Start Emterprise Manager"
#su - oracle -c "emctl start dbconsole"

# start isqlplus
#echo "Start isqlplus"
#su - oracle -c "isqlplusctl start"

;;
stop)
#when system stop redhat check /var/lock/subsys/oracle
#to make sure oracle is running.
rm -rf /var/lock/subsys/oracle

# shutdown database
echo "Shutdown Oracle database instance"
su - oracle -c "echo "
CONN / AS SYSDBA
SHUTDOWN immediate
exit "|sqlplus /NOLOG"

# stop tsnlisnter
echo "Stop tsnlisnter"
su - oracle -c "lsnrctl stop"

# stop enterprise manager
#echo " Stop Emterprise Manager"
#su - oracle -c "emctl stop dbconsole"

# stop isqlplus
#echo "Stop isqlplus"
#su - oracle -c "isqlplusctl stop"

;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
##########end of /etc/init.d/oracle################

轉自http://blog.chinaunix.net/u/7667/showart_64201.html

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/633084/viewspace-917362/,如需轉載,請註明出處,否則將追究法律責任。

相關文章