tomcat多实例启动脚本

#!/bin/bash
CURRENT_PATH=`pwd`
IFS_old=$IFS
IFS=$'\n'
instances=(instance1 instance2 instance3 instance4)

#export tomcat CATALINA_OUT so that unify logging
export CATALINA_OUT="$CURRENT_PATH"/logs/catalina.out

#export tomcat CATALINA_OPTS
export CATALINA_OPTS="-server -Xms200m -Xmx200m"

#shut single
shutSingle(){
	#shut tomcat use kill
	for line in $(ps -ef|grep "tomcat-9.0.36/$1")
	do
		if [[ $line == *bootstrap* ]];then
			ins_pid=$(echo $line|awk '{print $2}')
			kill -9 $ins_pid
			echo "========$1 shutdown it's pid is $ins_pid==========="
		fi
	done
}

#shut all
shutAll(){
	for ins in ${instances[@]}
	do
		shutSingle $ins
	done
}

#startup single
startSingle(){
	export CATALINA_BASE="$CURRENT_PATH/$1"
	$CURRENT_PATH/bin/startup.sh
	portStr=$(grep 'tor.*protocol="HTTP/1.1"' "$CURRENT_PATH/$1/conf/server.xml")
	portStr=$(echo ${portStr##*port=\"})
	echo "==========$1 startup port is ${portStr%%\" proto*}==========="
	echo $IFS
}

#start all
startAll(){
	for ins in ${instances[@]}
	do
		startSingle $ins
	done
}

#shut nginx
shutNginx(){
	for line in $(ps -ef|grep "nginx")
	do
		if [[ $line == *process* ]];then
			#shutdown nginx
			ins_pid=$(echo $line|awk '{print $2}')
			kill -9 $ins_pid
		fi
	done
	echo "========nginx shutdown==========="
}

#start nginx
startNginx(){
	echo "========nginx start==========="
	/usr/local/nginx/sbin/nginx
}

#check parameter
checkParam(){
	ins=$(echo "${instances[@]}" | grep -wq "$1" &&  echo "Y" || echo "N")
	if [ "$ins" = "N" ];then
		echo "second parameter is invalid"
		return 1
	fi
}

case "$1" in
   "shut") 
		checkParam $2
		if [ $? -eq 0 ];then
			shutSingle $2
		fi
   ;;
   "shutAll")
		shutAll
   ;;
   "start")
		checkParam $2
		if [ $? -eq 0 ];then
			startSingle $2
		fi
   ;;
   "startAll")
		startAll
   ;;
   "restart")
		checkParam $2
		if [ $? -eq 0 ];then
			shutSingle $2
			startSingle $2
		fi
   ;;
   "restartAll")
		shutAll
		startAll
   ;;
   "shutNginx")
		shutNginx
   ;;
   "startNginx")
		startNginx
   ;;
   "restartNginx")
		shutNginx
		startNginx
   ;;
   *) 
		echo "invalid command"
   ;;
esac

IFS=$IFS_old
#!/bin/bash
IFS_old=$IFS
IFS=$'\n'
for line in $(ps -ef|grep "nginx")
do
	if [[ $line == *process* ]];then
		#shutdown nginx
		ins_pid=$(echo $line|awk '{print $2}')
		kill -9 $ins_pid
	fi
done
echo "========nginx shutdown==========="

echo $IFS

#startup nginx
if [ -z "$1" ] ; then
	echo "========nginx restart==========="
	/usr/local/nginx/sbin/nginx
fi

IFS=$IFS_old

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值