1.查看当前启动的engine服务的tomcat进程的pid

1
pid=$(ssh root@$_ip  ps -ef | grep tomcat | grep cms | awk '{print $2}')

2.杀掉进程

1
ssh root@_ip kill -9 pid

3.远程启动

1
ssh root@ip "source /etc/profile;/usr/local/tomcat-cms/bin/catalina.sh start"

4.脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function tomcat_func(){
source_array=${1}
_ip=${2}
for server in ${source_array};
do
pid=$(ssh root@$_ip ps -ef | grep ${server} | grep -v "grep" | awk '{print $2}')
if [ ! $pid ];then
ssh root@$_ip "source /etc/profile;/usr/local/${server}/bin/catalina.sh start"
echo "${server} started..."
else
echo "${server} is running ..."
ssh root@$_ip "kill -9 $pid"
echo "${server} stopping..."
ssh root@$_ip "source /etc/profile;/usr/local/${server}/bin/catalina.sh start"
echo "${server} started..."
fi
echo ".............."
done
}

tomcat=("tomcat-dubbo-admin" "tomcat-engine" "tomcat-track")
tomcat_ip="172.18.100.20"
tomcat_func "${tomcat[*]}" $tomcat_ip