jar包启动或关闭脚本
启动jar包脚本start_or_stop.sh
:
#!/bin/bash
app='/usr/local/ccs_middle/middle-2.0.0.jar'
yml='/usr/local/ccs_middle/application-dev.yml'
LOGS_FILE=/usr/local/ccs_middle/ccs_middle.log
cmd=$1
pid=`ps -ef|grep java|grep $app|awk '{print $2}'`
startup(){
aa=`nohup java -jar $app --spring.config.location=$yml >> $LOGS_FILE 2>&1 &`
echo $aa
echo "ccs_middle startup succeeded";
}
if [ ! $cmd ]; then
echo "Please specify args 'start|restart|stop'"
exit
fi
if [ $cmd == 'start' ]; then
if [ ! $pid ]; then
startup
else
echo "$app is running! pid=$pid"
fi
fi
if [ $cmd == 'restart' ]; then
if [ $pid ]
then
echo "$pid will be killed after 3 seconds!"
sleep 3
kill -9 $pid
fi
startup
fi
if [ $cmd == 'stop' ]; then
if [ $pid ]; then
echo "$pid will be killed after 3 seconds!"
sleep 3
kill -9 $pid
fi
echo "$app is stopped"
fi
如何使用:
# 启动
sh start_or_stop.sh start
# 关闭
sh start_or_stop.sh stop
# 重启
sh start_or_stop.sh restart