#!/bin/bash
tomcatPath="/app/tomcat/apache-tomcat-9.0.54"
binPath="$tomcatPath/bin"
echo "[info][$(date)]正在监控tomcat,路径: $tomcatPath"
pid=`ps -ef | grep tomcat | grep -w $tomcatPath | grep -v 'grep' | awk '{print $2}'`
if [ -n "pid" ]; then
echo "[info][$(date)] tomcat进程为:$pid"
echo "[info][$(date)]tomcat已经启动,准备使用shutdown命令关闭 "
$binPath"/shutdown.sh"
sleep 2
pid=`ps -ef | grep tomcat | grep -w $tomcatPath | grep -v 'grep' | awk '{print $2}'`
if [ -n "$pid" ]; then
echo "[info][$(date)]使用shoutdown关闭失败,准备kill进程"
kill -9 $pid
echo "[info][$(date)]kill进程完毕"
sleep 1
else
echo "[info][$(date)]使用shutdown关闭成功"
fi
else
echo "[info][$(date)]tomcat未启动"
fi
echo "[info][$(date)]准备启动tomcat"
nohup $binPath"/startup.sh" &
echo "[info][$(date)]tomcat启动成功"