2019独角兽企业重金招聘Python工程师标准>>>
通用springboot微服务启动、停止脚本。
#!/bin/bash
#
# chkconfig: - 20 80
# description: Starts and stops the App.
# author:vakingeENV=dev
RUNNING_USER=vakinge
ADATE=`date +%Y%m%d%H%M%S`
APP_NAME=passport-serverAPP_HOME=`pwd`
dirname $0|grep "^/" >/dev/null
if [ $? -eq 0 ];thenAPP_HOME=`dirname $0`
elsedirname $0|grep "^\." >/dev/nullretval=$?if [ $retval -eq 0 ];thenAPP_HOME=`dirname $0|sed "s#^.#$APP_HOME#"`elseAPP_HOME=`dirname $0|sed "s#^#$APP_HOME/#"`fi
fiif [ ! -d "$APP_HOME/logs" ];thenmkdir $APP_HOME/logs
fiLOG_PATH=$APP_HOME/logs/$APP_NAME.out
GC_LOG_PATH=$APP_HOME/logs/gc-$APP_NAME-$ADATE.log
#JMX监控需用到
JMX="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1091 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
#JVM参数
JVM_OPTS="-Dname=$APP_NAME -Djeesuite.configcenter.profile=$ENV -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -Xloggc:$GC_LOG_PATH -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"JAR_FILE=$APP_NAME.jar
pid=0
start(){checkpidif [ ! -n "$pid" ]; thenJAVA_CMD="nohup java -jar $JVM_OPTS $JAR_FILE > $LOG_PATH 2>&1 &"su - $RUNNING_USER -c "$JAVA_CMD"echo "---------------------------------"echo "启动完成,按CTRL+C退出日志界面即可>>>>>"echo "---------------------------------"sleep 2stail -f $LOG_PATHelseecho "$APP_NAME is runing PID: $pid" fi}status(){checkpidif [ ! -n "$pid" ]; thenecho "$APP_NAME not runing"elseecho "$APP_NAME runing PID: $pid"fi
}checkpid(){pid=`ps -ef |grep $JAR_FILE |grep -v grep |awk '{print $2}'`
}stop(){checkpidif [ ! -n "$pid" ]; thenecho "$APP_NAME not runing"elseecho "$APP_NAME stop..."kill -9 $pidfi
}restart(){stop sleep 1sstart
}case $1 in start) start;; stop) stop;; restart) restart;; status) status;; *) echo "require start|stop|restart|status" ;;
esac