红联Linux门户
Linux帮助

菜鸟经验:oracle与weblogic自动启动与停止

发布时间:2006-02-15 08:48:04来源:红联作者:aini
最近做开发时,发觉每次重新启动服务器时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 "$1" 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)
$0 stop
$0 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 s cript
echo "kill -9 " `sed -n '1p' tmp02` > tmp03
#
chmod 755 tmp03
# kill weblogic
./tmp03
cd /home/weblogic/
sleep 3
rm -rfv zhouys
}

case "$1" 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)
$0 stop
#sleep 2 sec to stop all weblogic-process
sleep 2
$0 start
;;
*)
echo "Usage: $0 {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]# ln -s ../init.d/weblogic /etc/rc.d/rc6.d/K01weblogic

系统启动时启动weblogic,我们需要以下连结∶
[root@js-oracle init.d]# ln -s ../init.d/weblogic /etc/rc.d/rc2.d/S99weblogic
[root@js-oracle init.d]# ln -s ../init.d/weblogic /etc/rc.d/rc3.d/S99weblogic
[root@js-oracle init.d]# ln -s ../init.d/weblogic /etc/rc.d/rc5.d/S99weblogic



以上在RedHat Advance Server2.1版上配置 level 4 保留unused

三、 解释:
linux启动时:
图形界面 :自动调用/etc/rc.d/rc5.d下的符号连接名称以S开头(意为:start/启动)的脚本文件所指的服务,并自动传递命令行参数 start。
Linux关闭时:
图形界面 :自动调用/etc/rc.d/rc5.d下的符号连接名称以K开头(意为:kill/关闭)的文件所指的服务,并自动传递命令行参数 stop。

其它运行级别与此类似(具体可以参照/etc/rc.d/rc脚本)
文章评论

共有 68 条评论

  1. 69.147.76.* 于 2007-09-05 12:52:19发表:

    http://emeraldring.fora.pl/
    http://emeraldring.fora.pl/
    http://emeraldring.fora.pl/ - emerald cut wedding ring

  2. 68.180.195.* 于 2007-09-04 07:12:53发表:

    child defense fund
    child defense fund
    child defense fund - http://fund.freewebpages.org/child-defense-fund/index.html
    free fund raising idea
    free fund raising idea
    free fund raising idea - http://fund.freewebpages.org/free-fund-raising-idea/index.html
    fund raising company
    fund raising company
    fund raising company - http://fund.freewebpages.org/fund-raising-company/index.html

  3. 68.180.195.* 于 2007-09-02 06:27:04发表:

    Hi, nice very nice page..!
    fund
    alaska permanent fund dividend - http://fund.freewebpages.org/state-insurance-fund/index.html
    abb fund - http://fund.freewebpages.org/memorial-scholarship-fund/index.html
    fund raising counselor organization - http://fund.freewebpages.org/state-insurance-fund/index.html
    mutual fund company

    Good luck !
    PS: do you listen Linkin Park ?

  4. 61.28.1.* 于 2007-08-31 21:10:46发表:

    Hi, nice very nice page..!
    memorial scholarship fund - http://fund.freewebpages.org/state-insurance-fund/index.html
    abb fund
    fund
    cookie dough fund raiser - http://fund.freewebpages.org/abb-fund/index.html
    state insurance fund

    Good luck !
    PS: do you listen Linkin Park ?

  5. 219.141.223.* 于 2007-08-30 13:45:05发表:

    Hi, nice very nice page..!
    candy fund raising - http://fund.freewebpages.org/candy-fund-raising/index.html
    sample fund raising letter
    fund novel raising - http://fund.freewebpages.org/hedge-funds/index.html
    growth fund of america
    sample fund raising letter - http://fund.freewebpages.org/candy-fund-raising/index.html

    Good luck !
    PS: do you listen Linkin Park ?

  6. 68.180.195.* 于 2007-08-29 09:02:07发表:

    Hi, nice very nice page..!
    ford money market account
    high yield money market - http://www.volny.cz/bestmoney/make-money-in-stock-market/
    money market rate
    ford money market account
    high yield money market account

    Good luck !
    PS: do you listen Linkin Park ?

  7. 193.251.56.* 于 2007-08-27 18:53:05发表:

    Hi, nice very nice page..!
    best money market - http://volny.cz/capitalmoney/high-yield-money-market-account/
    money market funds
    money market account rate
    money market account rate
    vanguard money market funds - http://www.volny.cz/moneymarket1/money-market/

    Good luck !
    PS: do you listen Linkin Park ?

  8. 61.235.241.* 于 2007-08-25 22:00:47发表:

    Hi, nice very nice page..!
    best rate on money market account
    best money market rate
    vanguard money market funds
    best money market account
    best rate on money market account

    Good luck !
    PS: do you listen Linkin Park ?

  9. 0.0.0.* 于 2007-08-24 07:12:15发表:

    Hi, nice very nice page..!
    ford money market account
    money market funds
    best rate on money market account
    money market fund
    cnn money market stock - http://www.volny.cz/moneyrate/money-market-rate/

    Good luck !
    PS: do you listen Linkin Park ?

  10. 219.159.67.* 于 2007-08-09 16:25:22发表:

    Hi, nice very nice page..!
    buy pearl buy pearl buy pearl - http://volny.cz/buypearl
    pearl bridal jewelrypearl bridal jewelry pearl bridal jewelry - http://volny.cz/pearlbridaljewelry
    buy a pearl necklacebuy a pearl necklace buy a pearl necklace - http://volny.cz/buypearlnecklace
    blackberry buy pearl blackberry buy pearl blackberry buy pearl - http://volny.cz/blackberrybuypearl
    porsche 928 porsche 928 porsche 928 - www.volny.cz/porsche928

    Good luck !
    PS: do you listen Linkin Park ?

  11. 59.93.243.* 于 2007-08-07 17:48:21发表:

    desk lamp
    desk lamp - www.halogendesklamp.freehostia.com/desk-lamp/

    lamp shades
    lamp shades - www.halogendesklamp.freehostia.com/lamp-shades/

    office desk lamp
    office desk lamp - www.halogendesklamp.freehostia.com/office-desk-lamp/

  12. 217.141.105.* 于 2007-08-05 16:34:57发表:

    nice site... look on my site

    http://www.desklamp.fora.pl - desk lamp
    http://www.lampshades.fora.pl - lamp shades

  13. 219.141.223.* 于 2007-08-04 00:23:29发表:

    thnx... nice site
    and i wan't see my:
    http://www.tablelamp.fora.pl/
    http://www.tablelamp.fora.pl/
    http://www.tablelamp.fora.pl/ - table lamp

  14. 87.120.228.* 于 2007-08-04 00:23:14发表:

    thnx... nice site
    and i wan't see my:
    http://www.tablelamp.fora.pl/
    http://www.tablelamp.fora.pl/
    http://www.tablelamp.fora.pl/ - table lamp

  15. 67.52.10.* 于 2007-08-02 11:46:49发表:

    diesel ford truck used
    diesel ford truck used
    diesel ford truck used - http://www.bcars.fora.pl/

    car insurance quote
    car insurance quote
    car insurance quote - http://www.carinsurancequote.fora.pl/

  16. 62.231.243.* 于 2007-08-02 08:32:04发表:

    extreme torture drawings http://cartoonfox.150m.com/extreme_torture_drawings.html extreme torture drawings extreme torture drawings

    extreme comix xxx http://cartoonfox.150m.com/extreme_comix_xxx.html extreme comix xxx extreme comix xxx

    d bondage toons http://cartoonfox.150m.com/d_bondage_toons.html d bondage toons d bondage toons

    adult comics bondage toon http://cartoonfox.150m.com/adult_comics_bondage_toon.html adult comics bondage toon adult comics bondage toon

    extreme muscle drawings http://cartoonfox.150m.com/extreme_muscle_drawings.html extreme muscle drawings extreme muscle drawings

  17. 0.0.0.* 于 2007-07-31 18:41:02发表:

    gmc trucks here www.gmctruck.fora.pl
    gmc from america www.gmctruck.fora.pl
    real gmc www.gmctruck.fora.pl


    and www.emeraldring.fora.pl rings

  18. 62.231.243.* 于 2007-07-30 22:45:47发表:

    emerald rings and gold rings www.emeraldring.fora.pl

  19. 71.234.243.* 于 2007-07-19 02:21:45发表:

    adult comic hentai manga http://adultcomics17jul.tripod.com/adult_comic_hentai_manga.html adult comic hentai manga adult comic hentai manga
    adult comic sample http://adultcomics17jul.tripod.com/adult_comic_sample.html adult comic sample adult comic sample
    adult best comic free gallery http://adultcomics17jul.tripod.com/adult_best_comic_free_gallery.html adult best comic free gallery adult best comic free gallery
    adult archie comic http://adultcomics17jul.tripod.com/adult_archie_comic.html adult archie comic adult archie comic
    adult hot comic http://adultcomics17jul.tripod.com/adult_hot_comic.html adult hot comic adult hot comic

  20. 83.165.86.* 于 2007-07-17 18:35:27发表:

    http://365e51c62dce3fe4a43f8dacf44d1679-t.xkktxb.org 365e51c62dce3fe4a43f8dacf44d1679 http://365e51c62dce3fe4a43f8dacf44d1679-b1.xkktxb.org 365e51c62dce3fe4a43f8dacf44d1679 http://365e51c62dce3fe4a43f8dacf44d1679-b3.xkktxb.org 8d1f2bfe3cbc5359328d95464cab8b7c