#!/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