创建脚本
vim /etc/init.d/tomcat
按insert键进行编辑
# !/bin/bash
# Description: start or stop the tomcat
# Usage: tomcat [start|stop|restart] [25000|25004] --help
#
#
PATH_25000="/data/iuap/middleware/apache-tomcat-25000/bin/"
#PATH_25004="/data/iuap/middleware/apache-tomcat-25004/bin/"
#PATH_25008="/data/iuap/middleware/apache-tomcat-25008/bin/"
#PATH_25012="/data/iuap/middleware/apache-tomcat-25000/bin/"
if [ "$1" == "--help" ];then
echo "Description: start or stop the tomcat";
echo "Usage: tomcat [start|stop|restart] [port]";
fi
case "$2" in
25000)
case "$1" in
start)
echo "Starting tomcat 25000 !"
sh $PATH_25000/startup.sh;;
stop)
echo "Stoping tomcat 25000 !"
sh $PATH_25000/shutdown.sh;;
restart)
echo "Stoping tomcat 25000 !"
sh $PATH_25000/shutdown.sh
echo "String tomcat 25000 !"
sh $PATH_25000/startup.sh;;
esac
;;
#25004) echo "端口为25004";;
#25008) echo "端口为25008";;
#25012) echo "端口为25012";;
esac
编辑完成后输入 :wq 退出保存
脚本中共有两个参数,第一个为tomcat的状态,第二个为tomcat的端口
脚本添加执行权限
chmod +x /etc/init.d/tomcat
创建软连接
cd /usr/bin
ln -s /etc/init.d/tomcat .
测试
service tomcat stop 25000
service tomcat start 25000
service tomcat restart 25000
前面的service也可以不需要
注意
tomcat服务器自带的shutdown.sh不会杀死线程,而是让线程进入休眠状态,如何让shutdown.sh杀死线程请自行查询一下,很简单