关于tomcat快速启动及自动重启的方法与脚本

1、值班时会遇到tomcat服务需要手动重启的问题,为减少对应用的影响、提高响应速度,可以将tomcat启动(或重启)写成类似系统服务启动或重启的方式,

比如: 直接在命令行下输入(任意路径下)
引用 
[root@localhost]# tomcat [start|stop|reload|restart] 
即可完成启动、停止及重启操作。

优点是:不用每次启动或重启前都去查阅系统维护文档,减少了非常多的当机时间。(经测试,现在重启tomcat,只需要几秒钟时间)

2、当linux系统重启后,也不用人为去手动启动tomcat服务,十分方便。

下面详细解释一下如何建立这种脚本(以下是9服务器上的真实案例):

1、建立启动脚本(/etc/init.d/tomcat)
------------------------------------------code start---------------------------------------------------------
#
# !/bin/bash
# Description: start or stop the tomcat 
# Usage: tomcat [start|stop|reload|restart]
# Author: Wang Yinghui
# Date: Thu Apr 26, 2007
#

export PATH=$PATH:$HOME/bin
export BASH_ENV=$HOME/.bashrc
export USERNAME="root"

case "$1" in 
start) 
#startup the tomcat
 echo -n "tomcat start: "
cd /home/tomcat-5.5.20/bin/
. myconfig.sh
./startup.sh
cd /home/tomcat-5.5.20_second
. myconfig.sh
./startup.sh
 echo "finished" 
;; 
stop) 
# stop tomcat 
 echo -n "tomcat stop:" 
 ps -ef | grep "java" | grep -v grep | sed s/ [ ]*/:/g|cut -d: -f2| kill -9 `cat`
 echo "finished" 
;; 
reload|restart) 
 $0 stop 
 $0 start 
;; 
*) 
 echo "Usage: tomcat [start|stop|reload|restart]" 
 exit 1

esac 
exit 0 
-------------------------------------------code end--------------------------------------------------------------------

2、更改tomcat脚本为可执行文件
引用 
[root@localhost]# chmod 755 /etc/init.d/tomcat
3、为了在任意路径都可执行此脚本,需要添加到/usr/bin目录中
引用 
[root@localhost]# cd /usr/bin
[root@localhost]# ln -s /etc/init.d/tomcat .
4、使用方法 Usage: tomcat [start|stop|reload|restart],即:在任意路径中,直接输入: 
引用 
[root@localhost]# tomcat start (启动)
[root@localhost]# tomcat stop (停止)
[root@localhost]# tomcat restart (重启动)
5、为了让tomcat在操作系统重启以后自动启动,可以用如下方法简单解决:
引用 
[root@localhost]# ln -s /etc/init.d/tomcat /etc/rc.d/rc3.d/S99StartTomcat 
[root@localhost]# ln -s /etc/init.d/tomcat /etc/rc.d/rc5.d/S99StartTomcat

本篇文章来源于 xixis blog:http://www.wairi.cn 
原文链接:<a href="http://www.wairi.cn/article.%3Ca%20href=" http:="" www.2cto.com="" kf="" web="" asp="" "="" target="_blank" class="keylink" style="color: rgb(51, 51, 51); text-decoration: none;">asp?id=2604">http://www.wairi.cn/article.asp?id=2604

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值