restart.sh
#!/bin/bash
if [ "$1" != "" ] && [ "$1" != "-l" ]; then
echo "parameter is error, Usage: $0 or $0 -l"
exit 1
fi
#记忆当前目录
currpath=$PWD
#获取脚本所在的目录,也就是tomcat/bin目录
basepath=$(cd `dirname $0`; pwd)
#杀掉原来的进程
ps -ef | grep "$basepath" | grep -v 'grep' | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
#进入tomcat bin目录
cd $basepath
#删除原有日志文件
if [ "$1" = "-l" ]; then
rm -rf ../logs/*
fi
#重新启动
$basepath/startup.sh > /dev/null 2>&1 &
while true
do
if [ -f ../logs/catalina.out ]; then
break
fi
sleep 1s
done
#打开日志
tail -f -n0 ../logs/catalina.out
cd $currpath
exit 0