linux重启tomcat的shell脚本
基本思路:
先检查待重启的tomcat的进程是否存在
存在则执行shutdown.
然后再次检查进程是否还存在,不存在则执行kill
然后删除工作空间及10天前的日志。
最后执行启动。
#!/bin/sh
tomname="$1";
ctompath="/opt/tomcats/${tomname}"
echo "restart tomcat starting..."
pid=`ps -elf | grep ${ctompath} | grep -v grep | awk '{print $4}'`
echo "ps -elf | grep ${ctompath} | grep -v grep | awk '{print $4}'"
if [ -n "$pid" ]
then
{
echo ===========shutdown================
${ctompath}/bin/shutdown.sh
sleep 1
pid=`ps -elf | grep ${ctompath} | grep -v grep | awk '{print $4}'`
if [ -n "$pid" ]
then
{
sleep 1
echo ========kill tom first ==============
kill -9 $pid
sleep 1
echo ========kill tom second ==============
kill -9 $pid
}
fi
echo "rm -rf ${ctompath}/work/* "
rm -rf ${ctompath}/work/*
echo "rm -rf ${ctompath}/logs/* 10 days ago files "
find ${ctompath}/logs/ -mtime +10 -type f | xargs rm -rf
sleep 1
echo ===========startup.sh==============
${ctompath}/bin/startup.sh
}
else
echo ===========startup.sh==============
${ctompath}/bin/startup.sh
fi
echo "restart tomcat complete!!!"