startup.sh 启动脚本
#!/bin/sh
RESOURCE_NAME=./【要启动的jar包名】.jar
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'App is running.'
else
echo 'App is NOT running.'
fi
rm -f tpid
nohup java -Xms128m -Xmx1024m -jar ./$RESOURCE_NAME > catalina.out &
echo $! > tpid
echo Start Success!
shutdown.sh 停止脚本
#!/bin/sh
RESOURCE_NAME=./【要关闭的jar包名】.jar
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
使用
把 jar包,startup.sh 和 shutdown.sh 这3个文件放到同一个文件夹里
cd 到该路径
sh startup.sh #启动和重启 sh shutdown.sh #停止 tail -f catalina.out #实时查看运行日志