#!/bin/bash
# Apache Tomcat daemon
# chkconfig: 345 10 10
# description: Apache Tomcat daemon
# processname: tomcat
#定义JAVA_HOME
export JAVA_HOME=/app/jdk1.8
#定义多个tomcat的总目录,/app/tomcatserver目录下有tomcat6001,tomcat7001,tomcat8001,tomcat9001 四个tomcat实例。
tom="/app/tomcatserver/tomcat"
#定义启动脚本路径
startup_bin="bin/startup.sh"
#定义tomcat的启动方式,启动方式为tomcat.sh p1 start类似的命令
usage="{p1 args |p2|p3|all} {start|stop|restart|status}"
dev="/dev/null"
#定义如何启动tomcat,在此我们是通过个数tomcat以及前面定义的tomcat的命令,来操作tomcat
#judge $1 $2 whether null
if [ "$1" == "" -o "$2" == "" ];then
echo "Usage: $0 $usage"
exit 1
fi
#judge $1
case $1 in
"p1")
tomcats=$2
;;
"p2")
tomcats="6001 7001"
;;
"p3")
tomcats="6001 7001 8001"
;;
"all")
tomcats="6001 7001 8001 9001"
;;
# *)
# echo "Usage: $0 $usage"
#;;
esac
#定义tomcat的启动
#define start function
tomcatstart() {
for i in $tomcats
do
tom_home="$tom$i"
run_status=$(ps -ef | grep -v 'grep' | egrep "java.*=${tom_home}")
if [ "${run_status}X" != "X" ];then
echo "tomcat$i is already running…"
else
${tom_home}/${startup_bin} &>$dev
echo "tomcat$i starting,Please wait 2s…"
sleep 2
fi
done
}
#定义tomcat的关闭
#define stop function
tomcatstop() {
for j in $tomcats
do
tom1_home="$tom$j"
tomcat_pid=$(ps -ef | grep ${tom1_home} | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $2}')
if [ "${tomcat_pid}X" == "X" ];then
echo "tomcat$j is not running…"
else
kill -9 ${tomcat_pid} & >$dev
echo "tomcat$j stopping,Please wait 1s…"
sleep 1
echo "delte tomcat$j cache,Please wait 1s…"
rm -rf ${tom1_home}/work/*
fi
done
}
#定义tomcat的重启
#define restart function
tomcatrestart() {
for m in $tomcats
do
tom2_home="$tom$m"
run2_status=$(ps -ef | grep -v 'grep' | egrep "java.*=${tom2_home}")
if [ "${run2_status}X" == "X" ];then
echo "tomcat$m is not running…"
${tom2_home}/${startup_bin} &>$dev
echo "tomcat$m starting,Please wait 2s…"
sleep 2
else
ps -ef | grep ${tom2_home} | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $2}'| xargs kill -9 >$dev
echo "tomcat$m stopping,Please wait 2s…"
sleep 1
${tom2_home}/${startup_bin} &>$dev
echo "tomcat$m starting,Please wait 2s…"
sleep 2
fi
done
}
#定义tomcat的状态
#define status function
tomcatstatus() {
for n in $tomcats
do
tom3_home="$tom$n"
run3_status=$(ps -ef | grep -v 'grep' | egrep "java.*=${tom3_home}")
if [ "${run3_status}X" == "X" ];then
echo "tomcat$n is not running…"
else
echo "tomcat$n is running"
fi
done
}
#judge $2 $3
if [ "$3" == "" ];then
case $2 in
"start")
tomcatstart
;;
"stop")
tomcatstop
;;
"restart")
tomcatrestart
;;
"status")
tomcatstatus
;;
*)
echo "Usage: $0 $usage"
;;
esac
else
case $3 in
"start")
tomcatstart
;;
"stop")
tomcatstop
;;
"restart")
tomcatrestart
;;
"status")
tomcatstatus
;;
*)
echo "Usage: $0 $usage"
;;
esac
fi
管理tomcat单机多实例脚本
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 至少10年了,没在一线玩过 Tomcat 了,这次客户现场就来了一场遭遇战。虽然客户说了他来搭建,但是项目进度不等...