日期:2014-05-16  浏览次数:20802 次

linux下tomcat启动脚本

最近几天帮忙做应用测试,需要在linux下部署10个tomcat,挨个启动太麻烦了,负责人要求写个脚本批量处理。

我对linux脚本编写没什么概念,从网上参考了些资料,拼凑了一个脚本文件,勉强可以使用。

测试脚本期间遇到一个搞笑的事儿:10个start_tomcat命令依次执行,tomcat不能正常启动;于是有人猜想是不是启动太快造成的,建议在start_tomcat之间添加sleep 10,tomcat还是不能正常启动;有人提议在每个命令执行前添加了echo -n "Starting tomcatx",没有希望的尝试,结果出人意料居然成功执行,呵呵,因为大家对系统和脚本都不了解,所以“神奇的echo”在那天下班后的时间里成了我们的笑谈,呵呵。

?

#filename tomcat10.sh

export JAVA_HOME=/usr/java/jdk1.5.0_17
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin

?

cd /

?

start_tomcat1=home/dhcc/tomcat/apache-tomcat-1/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat2=home/dhcc/tomcat/apache-tomcat-2/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat3=home/dhcc/tomcat/apache-tomcat-3/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat4=home/dhcc/tomcat/apache-tomcat-4/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat5=home/dhcc/tomcat/apache-tomcat-5/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat6=home/dhcc/tomcat/apache-tomcat-6/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat7=home/dhcc/tomcat/apache-tomcat-7/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat8=home/dhcc/tomcat/apache-tomcat-8/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat9=home/dhcc/tomcat/apache-tomcat-9/apache-tomcat-6.0.18/bin/startup.sh
start_tomcat10=home/dhcc/tomcat/apache-tomcat-10/apache-tomcat-6.0.18/bin/startup.sh


stop_tomcat1=home/dhcc/tomcat/apache-tomcat-1/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat2=home/dhcc/tomcat/apache-tomcat-2/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat3=home/dhcc/tomcat/apache-tomcat-3/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat4=home/dhcc/tomcat/apache-tomcat-4/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat5=home/dhcc/tomcat/apache-tomcat-5/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat6=home/dhcc/tomcat/apache-tomcat-6/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat7=home/dhcc/tomcat/apache-tomcat-7/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat8=home/dhcc/tomcat/apache-tomcat-8/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat9=home/dhcc/tomcat/apache-tomcat-9/apache-tomcat-6.0.18/bin/shutdown.sh
stop_tomcat10=home/dhcc/tomcat/apache-tomcat-10/apache-tomcat-6.0.18/bin/shutdown.sh


start(){
?echo -n "Starting tomcat1"
?${start_tomcat1}
?
?echo -n "startint tomcat2"?
?${start_tomcat2}
?
?echo -n "startint tomcat3"?
?${start_tomcat3}
?
?echo -n "startint tomcat4"?
?${start_tomcat4}
?
?echo -n "startint tomcat5"?
?${start_tomcat5}
?
?echo -n "startint tomcat6"?
?${start_tomcat6}
?
?echo -n "startint tomcat7"?
?${start_tomcat7}
?
?echo -n "startint tomcat8"?
?${start_tomcat8}
?
?echo -n "startint tomcat9"?
?${start_tomcat9}
?
?echo -n "startint tomcat10"?
?${start_tomcat10}
?
?echo "tomcat start ok."
}

stop() {
?echo -n "stop tomcat1: "
?${stop_tomcat1}
?
?echo -n "stop tomcat2: "
?${stop_tomcat2}
?
?echo -n "stop tomcat3: "
?${stop_tomcat3}
?
?echo -n "stop tomcat4: "
?${stop_tomcat4}
?
?echo -n "stop tomcat5: "
?${stop_tomcat5}
?
?echo -n "stop tomcat6: "
?${stop_tomcat6}
?
?echo -n "stop tomcat7: "
?${stop_tomcat7}
?
?echo -n "stop tomcat8: "
?${stop_tomcat8}
?
?echo -n "stop tomcat9: "
?${stop_tomcat9}
?
?echo -n "stop tomcat10: "
?${stop_tomcat10}
?
?echo "tomcat stop ok."
}

# See how we were called
case "$1" in
start)
?start
?;;

stop)?
stop?
;;?

restart)?
stop?
sleep 10
start?
;;

*)?
echo "Usage: $0 {start|stop|restart}"

esac

exit 0


######################################################
#Like this you can now enter the command in a terminal

#sh tomcat10.sh start? or sh