oracle与weblogic自动启动与停止


最近做开发时,发觉每次重新启动服务器时oracle数据库若没有关闭,则必须先关闭后在重新启动redhat advance server,oracle才能够正常运行。感觉这样麻烦,想到能否使数据库与web服务器与操作系统一同关闭与启动。在网上查找了一下相关资料,只找到一篇“Oracle Database HOWTO 自动启动及停止.htm”但是没有找到有关weblogic自动启动与停止的文章。经过摸索,我最初的想法实现了,因此想把它写出来,与大家交流。
服务器环境:
RedHat Advance Server2.1
Oracle 9.2.2 for Linux
Weblogic7.0 for Linux
一、 oracle自动启动与停止
1、 修改Oracle系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。我的为:
ora9i:/home/oracle/ora/products/9.2.0:Y
2、 编写服务脚本:如下
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Oracle and listener
# AutoStop Oracle and listener
#
#####################################
#
# Created by ZhouYS 2003-11-26
#

case "{GetProperty(Content)}" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbstart" >> /var/log/oracle
echo "Done."
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle

;;
stop)
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle

;;
restart)
{GetProperty(Content)} stop
{GetProperty(Content)} start

;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

将脚本命名为oracle,保存在/etc/rc.d/init.d下
改变文件属性:chmod 755 oracle

注意:在windows下编辑此文件时有DOS格式字符导致在linux下不能够正常运行,建议用gedit 或用 vi编辑

3、建立服务连接:
系统启动时启动数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused


--------------------------------------------------------------------------------

要在重新启动时停止数据库,我们需要以下连结∶


--------------------------------------------------------------------------------

$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新启动
二、weblogic自动启动与停止
假设weblogic安装在/home/weblogic/bea下。
1、 编写服务脚本:如下
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Weblogic
# AutoStop Weblogic
#
#####################################
#
# Created by ZhouYS 2003-11-26
# Wellhope Information Technology Co.,Ltd
# PUJIANG Science Park(浦江科学园)
#
shutdownweblogic()
{
cd /
# make temp work dir ,you can create it in /tmp
mkdir -p /home/weblogic/zhouys
#
cd /home/weblogic/zhouys
#find weblogic main process
ps -aux | grep /home/weblogic >tmp01
#
awk '{print $2}' tmp01 | sort > tmp02
#produce kill-main-process script
echo "kill -9 " `sed -n '1p' tmp02` > tmp03
#
chmod 755 tmp03
# kill weblogic
./tmp03
cd /home/weblogic/
sleep 3
rm -rfv zhouys
}

case "{GetProperty(Content)}" in
start)
echo "Starting Weblogic ... "
echo "-------------------------------------------------" >> /var/log/weblogic
date +" %T %a %D : Starting Weblogic as part of system up." >> /var/log/weblogic
echo "-------------------------------------------------" >> /var/log/weblogic
cd /home/weblogic/bea/user_projects/mydomain/ >> /dev/null
. startWebLogic.sh & >> /var/log/weblogic
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/weblogic
date +" %T %a %D : Finished." >> /var/log/weblogic
echo "-------------------------------------------------" >> /var/log/weblogic
touch /var/lock/subsys/weblogic

;;
stop)
echo "Stopping Weblogic ... "
echo "-------------------------------------------------" >> /var/log/weblogic
date +" %T %a %D : Stopping Weblogic as part of system down." >> /var/log/weblogic
echo "-------------------------------------------------" >> /var/log/weblogic
shutdownweblogic
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/weblogic
date +" %T %a %D : Finished." >> /var/log/weblogic
echo "-------------------------------------------------" >> /var/log/weblogic

;;
restart)
{GetProperty(Content)} stop
#sleep 2 sec to stop all weblogic-process
sleep 2
{GetProperty(Content)} start
;;
*)
echo "Usage: {GetProperty(Content)} {start|stop|restart}"
exit 1
esac

将脚本命名为weblogic,保存在/etc/rc.d/init.d下
改变文件属性:chmod 755 weblogic

注意:在windows下编辑此文件时有DOS格式字符导致在linux下不能够正常运行,建议用gedit 或用 vi编辑, shutdownweblogic函数中没有加入错误控制,各位可以自己完善。
2、 建立服务连接:
要在重新启动时停止weblogic,我们需要以下连结∶
[root@js-oracle init.d]# ln -s ../init.d/weblogic /etc/rc.d/rc0.d/K01weblogic
[root@js-oracle init.d]

本文作者:



相关阅读:
MySQL使用指南(二)
UCHome首页调用修改方法
通过对php一些服务器端特性的配置加强php的安全
PEAR DB_Table 简介
封装常用javascript以便PHP快速调用
根据日期知道当天是星期几的手动计算方法
dos、bat批处理延时执行命令的两种方法
Linux网络备份MYSQL
写一个bat批处理文件启动windows进程和延时关闭的代码
SQL Server中临时表与表变量的区别
ASP 类 Class入门 推荐
用VNC远程图形化连接Linux桌面的配置方法
第三章 php操作符与控制结构代码
JavaScript滑移效果代码
快速导航

Copyright © 2016 phpStudy |