针对普通的可执行的jar文件,提供启动,停止,重启等功能
配置JVM参数: 打印GC日志,当内存溢出OOM时导出一份heapdump
假设脚本名字叫app.sh
那么:
-
给app.sh添加可执行权限: chmod +x app.sh
-
启动项目: ./app.sh start
-
停止项目: ./app.sh stop
-
重启项目: ./app.sh restart
#!/bin/bash
针对普通的可执行的jar文件,提供启动,停止,重启等功能
需要根据jar包名称更改APP_JAR
ms 和 mx 也需要根据情况调整
SHELL_FOLDER= ( c d " (cd " (cd"(dirname “ 0 " ) " ; p w d ) A P P J A R = " x x l − j o b − a d m i n − 2.2.0. j a r " L O G P A T H = 0")";pwd) APP_JAR="xxl-job-admin-2.2.0.jar" LOG_PATH= 0")";pwd)APPJAR="xxl−job−admin−2.2.0.jar"LOGPATH=SHELL_FOLDER/logs
JAVA_OPTS=”
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCCause
-Xloggc: L O G P A T H / g c . l o g − X X : + H e a p D u m p O n O u t O f M e m o r y E r r o r − X X : H e a p D u m p P a t h = LOG_PATH/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= LOGPATH/gc.log−XX:+HeapDumpOnOutOfMemoryError−XX:HeapDumpPath=LOG_PATH/heapdump
-Dfile.encoding=utf-8"start(){
if [ ! -d “ L O G P A T H " ] ; t h e n m k d i r " LOG_PATH" ];then mkdir " LOGPATH"];thenmkdir"LOG_PATH”
fi
nohup java $JAVA_OPTS -jar S H E L L F O L D E R / SHELL_FOLDER/ SHELLFOLDER/APP_JAR >$LOG_PATH/console.log 2>&1 &
echo “app S H E L L F O L D E R / SHELL_FOLDER/ SHELLFOLDER/APP_JAR started.”
echo “JAVA_OPTS: $JAVA_OPTS”
}stop(){
ps -ef|grep S H E L L F O L D E R / SHELL_FOLDER/ SHELLFOLDER/APP_JAR|grep -v grep|awk ‘{print $2}’|xargs kill -9
echo “app S H E L L F O L D E R / SHELL_FOLDER/ SHELLFOLDER/APP_JAR is killed.”
}restart(){
stop
start
}echo “APP_HOME:$SHELL_FOLDER”
case $1 in
“start”)
start
;;
“stop”)
stop
;;
“restart”)
restart
;;
*)
echo “Usage: app.sh ( commands … )”
echo “commands:”
echo " start Start java app"
echo " stop Stop java app"
echo " restart Restart java app"
;;
esac