自定义linux启动jar包脚本
JAR_NAME="/opt/test/server/test-module-system-3.4.0.jar"
LOG_PATH=/opt/test/server/nohup.out
tips() {
echo ""
echo "WARNING!!!......Tips, please use command: sh auto_deploy.sh [start|stop|restart|status]. For example: sh auto_deploy.sh start "
echo ""
exit 1
}
start() {
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -z $pid ]; then
nohup java -jar $JAR_NAME >$LOG_PATH 2>&1 &
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
echo ""
echo "Service ${JAR_NAME} is starting!pid=${pid}"
echo "........................Here is the log.............................."
echo "....................................................................."
tail -f $LOG_PATH
echo "........................Start successfully!........................."
else
echo ""
echo "Service ${JAR_NAME} is already running,it's pid = ${pid}. If necessary, please use command: sh auto_deploy.sh restart."
echo ""
fi
}
stop() {
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -z $pid ]; then
echo ""
echo "Service ${JAR_NAME} is not running! It's not necessary to stop it!"
echo ""
else
kill -9 $pid
echo ""
echo "Service stop successfully!pid:${pid} which has been killed forcibly!"
echo ""
fi
}
status() {
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -z $pid ];then
echo ""
echo "Service ${JAR_NAME} is not running!"
echo ""
else
echo ""
echo "Service ${JAR_NAME} is running. It's pid=${pid}"
echo ""
fi
}
restart() {
echo ""
echo ".............................Restarting.............................."
echo "....................................................................."
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ ! -z $pid ]; then
kill -9 $pid
fi
start
echo "....................Restart successfully!..........................."
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
tips
;;
esac