当系统重启后,也不用人为去手动启动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
转载于:https://blog.51cto.com/lya041/1052226