1. 程式人生 > >shell 管理SpringBoot 生產環境服務 (新增main函式引數)

shell 管理SpringBoot 生產環境服務 (新增main函式引數)

前面寫過幾遍不同型別的生產環境管理命令

  1. 配置JVM 檢視
  2. 備份日誌 檢視
  3. 介面通知關閉 檢視
  4. 簡單實用 檢視

今天這裡整理給main函式新增引數的方法

#!/bin/bash

Tag="test"
MainClass="com.yokead.Application"
Lib="/test/admin/lib/"
Log="/test/admin/run.log"
echo $Tag
RETVAL="0"

# See how we were called.
function start() {
    echo  $Log 
    if [ ! -f $Log ]; then
        touch $Log
    fi
    nohup java -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass $arg  > $Log 2>&1 &  
    tailf $Log
}


function stop() {
	pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
	if [ "$pid" != "" ]; then 		
        echo -n "boot ( pid $pid) is running" 
        echo 
        echo -n $"Shutting down boot: "
		pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
		if [ "$pid" != "" ]; then
			echo "kill boot process"
			kill -9 "$pid"
		fi
        else 
             echo "boot is stopped" 
        fi

	status
}

function status()
{
	pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
	#echo "$pid"
	if [ "$pid" != "" ]; then
		echo "boot is running,pid is $pid"
	else
		echo "boot is stopped"
	fi
}



function usage()
{
   echo "Usage: $0 {start|stop|restart|status}"
   RETVAL="2"
}

# See how we were called.
RETVAL="0"
arg="$2"
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
      usage
      ;;
esac

exit $RETVAL

使用方法是:

./test.sh start test

這樣start 後面跟著引數值

這樣大家配合前面幾個方法,可以隨意組合出更高階的管理了,如果在使用過程中有疑問或者更好的建議歡迎隨機交流