下面贴一些方便的单机多实例部署tomcat的操作脚本,在实际使用中还是很方便的。
启动脚本:(需要相应设置YOUR_TOMCAT_DIR和YOUR_DEPLOY_DIR)
#!/bin/bashsource /etc/profileexport CATALINA_HOME=YOUR_TOMCAT_DIRif echo $1 | grep -q "YOUR_DEPLOY_DIR"then export CATALINA_BASE=${1%/}else export CATALINA_BASE=YOUR_DEPLOY_DIR/${1%/}fiinstance=`ls YOUR_DEPLOY_DIR | head -1`;if ! [ -e $CATALINA_BASE/conf/server.xml ]then echo -e " usage: $0 YOUR_DEPLOY_DIR/$instance\n" exit 1;fiif [ -r "$CATALINA_BASE"/env.sh ]; then . "$CATALINA_BASE"/env.shfiTOMCAT_ID=`ps aux |grep "java"|grep "Dcatalina.base=$CATALINA_BASE"|grep -v "grep"|awk '{ print $2}'`if [ -n "$TOMCAT_ID" ] ; then echo "tomcat(${TOMCAT_ITOMCAT_ID}) still running now , please shutdown it first"; exit 2;fiTOMCAT_START_LOG=`$CATALINA_HOME/bin/startup.sh`if [ "$?" = "0" ]; then echo "$0 ${1%/} start succeed"else echo "$0 ${1%/} start failed" echo $TOMCAT_START_LOGfi
停止脚本:
#!/bin/bashsource /etc/profileexport CATALINA_HOME=YOUR_TOMCAT_DIRif echo $1 | grep -q "YOUR_DEPLOY_DIR"then export CATALINA_BASE=${1%/}else export CATALINA_BASE=YOUR_DEPLOY_DIR/${1%/}fiinstance=`ls YOUR_DEPLOY_DIR | head -1`;if ! [ -e $CATALINA_BASE/conf/server.xml ]then echo -e " usage: $0 YOUR_DEPLOY_DIR/$instance\n" exit 1;fiTOMCAT_ID=`ps aux |grep "java"|grep "[D]catalina.base=$CATALINA_BASE "|awk '{ print $2}'`if [ -n "$TOMCAT_ID" ] ; then TOMCAT_STOP_LOG=`$CATALINA_HOME/bin/shutdown.sh`else echo "Tomcat instance not found : ${1%/}" exitfifor i in {1..10}; do TOMCAT_ID=`ps aux |grep "java"|grep "Dcatalina.base=$CATALINA_BASE "|grep -v "grep"|awk '{ print $2}'` if [ -n "$TOMCAT_ID" ]; then if [ "$i" = "1" ]; then echo -n "trying stop ($TOMCAT_ID): $i" else echo -n -e "\b$i" fi if [ $i -ge 5 ]; then kill "$TOMCAT_ID" fi sleep 1 else if [ $i -gt 5 ]; then echo -e "\n$TOMCAT_BASE was killed($i)" else echo -e "\n$TOMCAT_BASE was stopped" fi exit; fidone;kill -9 "$TOMCAT_ID"echo "$TOMCAT_BASE was force killed"
重启脚本:
#!/bin/bashCD_TO/stop_tomcat.sh $1CD_TO/start_tomcat.sh $1