通用springboot微服务启动、停止脚本。
#!/bin/bash## chkconfig: - 20 80# description: Starts and stops the App.# author:vakingeENV=devRUNNING_USER=vakingeADATE=`date +%Y%m%d%H%M%S`APP_NAME=passport-serverAPP_HOME=`pwd`dirname $0|grep "^/" >/dev/nullif [ $? -eq 0 ];then APP_HOME=`dirname $0`else dirname $0|grep "^\." >/dev/null retval=$? if [ $retval -eq 0 ];then APP_HOME=`dirname $0|sed "s#^.#$APP_HOME#"` else APP_HOME=`dirname $0|sed "s#^#$APP_HOME/#"` fifiif [ ! -d "$APP_HOME/logs" ];then mkdir $APP_HOME/logsfiLOG_PATH=$APP_HOME/logs/$APP_NAME.outGC_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.jarpid=0start(){ checkpid if [ ! -n "$pid" ]; then JAVA_CMD="nohup java -jar $JVM_OPTS $JAR_FILE > $LOG_PATH 2>&1 &" su - $RUNNING_USER -c "$JAVA_CMD" echo "---------------------------------" echo "启动完成,按CTRL+C退出日志界面即可>>>>>" echo "---------------------------------" sleep 2s tail -f $LOG_PATH else echo "$APP_NAME is runing PID: $pid" fi}status(){ checkpid if [ ! -n "$pid" ]; then echo "$APP_NAME not runing" else echo "$APP_NAME runing PID: $pid" fi }checkpid(){ pid=`ps -ef |grep $JAR_FILE |grep -v grep |awk '{print $2}'`}stop(){ checkpid if [ ! -n "$pid" ]; then echo "$APP_NAME not runing" else echo "$APP_NAME stop..." kill -9 $pid fi }restart(){ stop sleep 1s start}case $1 in start) start;; stop) stop;; restart) restart;; status) status;; *) echo "require start|stop|restart|status" ;; esac