Tomcat服务重启脚本
#此脚本适用于本地安装tomcat环境,操作脚本重启。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@ansible_clent ~]
# cat restart_tomcat.sh
#!/bin/bash
function
shutdown_tomcat () {
#tomcat_id=`jps | grep Bootstrap | awk '{print $1}'`
tomcat_id=`
lsof
-i:8080 |
awk
'NR==2'
'{print $2}'
`
if
[ ! $tomcat_id ];
then
echo
"tomcat process in ${ip} is not exist."
else
echo
"shoutdown ${ip} tomcat"
/bin/kill
-9 $tomcat_id
fi
}
function
start_tomcat () {
echo
"start $ip tomcat"
/bin/sh
/data/tomcat/bin/catalina
.sh start
/usr/local/java/bin/jps
}
function
restart_tomcat () {
shutdown_tomcat
start_tomcat
}
restart_tomcat
|
#此脚本限于在跳板机上使用操作Tomcat重启服务(机器之间做了ssh密钥认证)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[root@ansible_clent ~]
# cat restart_tomcat.sh
#!/bin/sh
cat
<<EOF
------------------------------------
重启某些ip的tomcat服务,ip地址以,隔开
------------------------------------
EOF
function
shutdown_tomcat() {
ip=$1
tomcat_id=`
ssh
$ip
ps
-ef |
grep
tomcat |
grep
-
v
grep
|
awk
'{print $2}'
`
if
[ ! $tomcat_id ];
then
echo
"tomcat process in ${ip} is not exist."
else
echo
"shutdown tomcat in ${ip}"
ssh
$ip
"/bin/kill -9 $tomcat_id"
fi
}
function
start_tomcat(){
ip=$1
echo
"start tomcat in ${ip}"
ssh
$ip
"JAVA_HOME=/usr/local/java/jdk1.7.0_80;export JAVA_HOME;/bin/sh /data/tomcat/bin/startup.sh"
ssh
$ip
"/usr/local/java/jdk1.7.0_80/bin/jps"
}
read
-p
"请输入你的ip地址列表[以,隔开]:"
pool_ip_list
all_list=`
awk
'BEGIN{list="'
$pool_ip_list
'";split(list,ip_list,",");for(ip in ip_list){print ip_list[ip];}}'
`
for
ip
in
${all_list[*]};
do
shutdown_tomcat $ip
start_tomcat $ip
done
|
本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1890913