一次性殺掉多個tomcat進程命令:
下面是進過改進版的restart.sh
#!/bin/sh
TOMCAT_PATH=/home/server/shichuan/bin
echo "TOMCAT_PATH is $TOMCAT_PATH"
PID=`ps aux | grep /home/server/shichuan/ | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "Will shutdown tomcat: $PID"
$TOMCAT_PATH/shutdown.sh -force
sleep 5
else echo "No Tomcat Process $PID"
fi
ps -ef|grep -v grep|grep /home/server/shichuan/ | grep java |awk '{print "kill -9 "$2}'|sh
sleep 1
$TOMCAT_PATH/startup.sh
sleep 50
for((i=1;i<5;i++))
do
LASTINFO=`tail -n 1 /home/server/shichuan/logs/catalina.out |grep 'INFO: Server startup in'`
if [ -n "$LASTINFO" ]; then
break
else
ps -ef|grep -v grep|grep /home/server/shichuan/ | grep java |awk '{print "kill -9 "$2}'|sh
sleep 1
$TOMCAT_PATH/startup.sh
sleep 50
fi
done
----------------------------------------
注意:一台服務器如果運行多個tomcat實例,不要配環境變量,容易啟動錯誤,除了端口變換外,
restart.sh腳本#{tomcat目錄}命名要區別,不然kill掉所有tomcat進程
TOMCAT_PATH為tomcat的bin目錄,前后不能有反引號
#!/bin/sh
TOMCAT_PATH=#{tomcat目錄}/bin
echo "TOMCAT_PATH is $TOMCAT_PATH"
PID=`ps aux | grep #{tomcat目錄} | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "Will kill tomcat: $PID"
sh "$TOMCAT_PATH/shutdown.sh"
sleep 6
else echo "No Tomcat Process $PID"
fi
PID2=`ps aux | grep #{tomcat目錄} | grep java | awk '{print $2}'`
if [ -n "$PID2" ]; then
kill -9 $PID2
echo "Try to kill $PID2"
else echo "No Tomcat Process $PID2"
fi
sh "$TOMCAT_PATH/startup.sh"
sleep 3
PID=`ps aux | grep #{tomcat目錄} | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "\nRestart tomcat successfully!"
else
echo "\nFail to startup tomcat"
exit 1
fi
===================================
停止腳本stop.sh
#!/bin/sh
TOMCAT_PATH=#{tomcat目錄}/bin
echo "TOMCAT_PATH is $TOMCAT_PATH"
PID=`ps aux | grep #{tomcat目錄} | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "Will kill tomcat: $PID"
sh "$TOMCAT_PATH/shutdown.sh"
sleep 6
else echo "No Tomcat Process $PID"
fi
PID2=`ps aux | grep #{tomcat目錄} | grep java | awk '{print $2}'`
if [ -n "$PID2" ]; then
kill -9 $PID2
echo "Try to kill $PID2"
else echo "No Tomcat Process $PID2"
fi
===================================
創建文件后需要給執行權限
chmod +x restart.sh
chmod +x stop.sh
或者設置成777等權限
重啟tomcat時到bin目錄下執行./restart.sh 就可以了
===================================
在window本地編輯sh上傳可能遇到下面問題,需要解決編碼問題

