经常有人会需要Oracle数据库随着操作系统一起启动和关闭,而修改/etc/oratab,设置了oracle SID行启动为Y时实际上是不好用的。本文以一个例子来示范如何去做。
[@more@]如下给的是一个example,注意部分内容可能要改,比如oracle的用户名。
1、在/sbin/init.d/目录下建立一个文件,并命名为oracle,并授予它555权限,更改它owner为bin:bin。
#!/bin/sh
#
# /etc/rc.d/init.d/oracle
# 解说∶启动及停止 Oracle 数据库和监听程序
# 检查如何执行脚本文件
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
su - oracle -c dbstart >> /var/adm/syslog/oracle.log
echo "Done."
echo -n "Starting Oracle Listeners: "
su - oracle -c "lsnrctl start" >> /var/adm/syslog/oracle.log
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Finished." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
su - oracle -c "lsnrctl stop" >> /var/adm/syslog/oracle.log
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - oracle -c dbshut >> /var/adm/syslog/oracle.log
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Finished." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
su - oracle -c dbstop >> /var/adm/syslog/oracle.log
su - oracle -c dbstart >> /var/adm/syslog/oracle.log
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - oracle -c "lsnrctl stop" >> /var/adm/syslog/oracle.log
su - oracle -c "lsnrctl start" >> /var/adm/syslog/oracle.log
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
date +"! %T %a %D : Finished." >> /var/adm/syslog/oracle.log
echo "----------------------------------------------------" >> /var/adm/syslog/oracle.log
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
2、建立runlevel directories下的符号链接
ln -s /sbin/init.d/oracle /sbin/rc3.d/S99orastart
ln -s /sbin/init.d/oracle /sbin/rc0.d/K01orastop
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/717880/viewspace-822534/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/717880/viewspace-822534/