centos 啟動(dòng)jar腳本
#!/bin/bash
APP_PATH=/home/admin/yemast/yuntu/roadcqc-rest/
APP_NAME=roadcqc_rest-0.0.1-SNAPSHOT.jar
#使用說(shuō)明,用來(lái)提示輸入?yún)?shù)
usage() {
echo "Usage: sh 腳本名.sh [start|stop|restart|status]"
exit 1
}
#檢查程序是否在運(yùn)行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
#啟動(dòng)方法
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
nohup java -jar $APP_PATH$APP_NAME > ./log.file 2>&1 &
echo "${APP_NAME} start success"
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
#輸出運(yùn)行狀態(tài)
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}
#重啟
restart(){
stop
start
}
#根據(jù)輸入?yún)?shù),選擇執(zhí)行對(duì)應(yīng)方法,不輸入則執(zhí)行使用說(shuō)明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac

浙公網(wǎng)安備 33010602011771號(hào)