tomcat启动检测

为防止tomcat启动但项目未能正确运行调用startup.sh 后定时检测index页面是否可以访问

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
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash  

tomcatPath="/user/apache-tomcat"
binPath="$tomcatPath/bin"
APP_NAME="tomcat"

echo "查询所有tomcat并停止"
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
if [ "${pid}" ]; then
for id in $pid
do
kill -9 $id
done
fi
echo "进程已停止"


echo "[info][$(date)]准备启动tomcat"
$binPath"/startup.sh"
if [ $? -eq 0 ]; then
echo "启动命令执行成功........"
echo "检查tomcat运行状态..."
for (( i=0; i<12; ++i ))
do
if [ $(curl -sIL -w "%{http_code}" -o /dev/null http://localhost:8080/login.html) -eq 200 ];then
echo "tomcat启动成功"
break
else
if [[ i -eq 11 ]];then
echo "tomcat启动失败,请查看tomcat日志"
exit 1
else
echo "tomcat正在启动中..."
sleep 5
fi
fi
done
else
echo "启动命令执行失败......."
fi