cetnos运行springboot打包文件脚本
#!/bin/bash #check JAVA_HOME & java noJavaHome=false if [ -z "$JAVA_HOME" ] ; then noJavaHome=true fi if [ ! -e "$JAVA_HOME/bin/java" ] ; then noJavaHome=true fi if $noJavaHome ; then echo echo "Error: JAVA_HOME environment variable is not set." echo exit 1 fi #主目录 BASE_DIR=$(cd $(dirname $0);cd ..;pwd) #执行程序的名称 APP_NAME=server-1.0-SNAPSHOT.jar #============================================================================== #set JAVA_OPTS JAVA_OPTS="-server -Xms2G -Xmx2G -XX:+AggressiveOpts -XX:MaxDirectMemorySize=2G" #JAVA_OPTS="-server -Xms4G -Xmx4G -XX:+AggressiveOpts -XX:MaxDirectMemorySize=6G" #performance Options #JAVA_OPTS="$JAVA_OPTS -Xss256k" #JAVA_OPTS="$JAVA_OPTS -XX:+AggressiveOpts" #JAVA_OPTS="$JAVA_OPTS -XX:+UseBiasedLocking" #JAVA_OPTS="$JAVA_OPTS -XX:+UseFastAccessorMethods" #JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC" #JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC" #JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC" #JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled" #JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSCompactAtFullCollection" #JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly" #JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75" #JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75" #GC Log Options #JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime" #JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" #JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" #debug Options #JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8065,server=y,suspend=n" #============================================================================== #============================================================================== #set JAVA_OPTS DEFAULT_SEARCH_LOCATIONS="classpath:/,file:./,file:./conf/" CUSTOM_SEARCH_LOCATIONS="${DEFAULT_SEARCH_LOCATIONS},file:${BASE_DIR}/conf/" JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health,${BASE_DIR}/plugins/cmdb,${BASE_DIR}/plugins/mysql,${BASE_DIR}/target/lib/" JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/${APP_NAME}" JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}" #============================================================================== #使用说明,用来提示输入参数 usage() { echo "Usage: sh service.sh [start|stop|restart|status]" exit 1 } #检查程序是否在运行 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 } #启动方法 start(){ is_exist if [ $? -eq 0 ]; then echo "${APP_NAME} is already running. pid=${pid}" else # nohup $JAVA_HOME/bin/java $JAVA_OPT >/dev/null 2>&1 & nohup $JAVA_HOME/bin/java $JAVA_OPT >${BASE_DIR}/logs/nohup.log & echo "..." sleep 2 echo "..." sleep 3 is_exist if [ $? -eq 0 ]; then echo "${APP_NAME} is running success. pid=${pid}" fi fi } #停止方法 stop(){ is_exist if [ $? -eq "0" ]; then kill -9 $pid echo "..." sleep 2 is_exist if [ $? -eq 0 ]; then echo "${APP_NAME} still in the running. pid=${pid}" else echo "${APP_NAME} has stopped running." fi else echo "${APP_NAME} is not running" fi } #输出运行状态 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 #sleep 5 start } #根据输入参数,选择执行对应方法,不输入则执行使用说明 case "$1" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esac exit 0