shell來start、stop、restart應用程序模板


這里使用shell中的case語法:

case分支語句格式如下:

case $變量名 in

  模式1)

  命令列表

  ;;

  模式2)

  命令列表

  ;;

  *)

  ;;

esac

case行尾必須為單詞“in”,每一個模式必須以右括號“)”結束。

雙分號“;;”表示命令序列結束。這里給一個編寫應用程序的start、stop、restart等操作的模板

#!/bin/sh
BASE_HOME=/home/apple/test
PID=${BASE_HOME}/.pid
status(){
   echo "==========status======="
}

start() {
    echo "==========start===========";
}

stop() {
    echo "===========stop============";
}

restart() {
    stop;
    echo "sleeping.........";
    sleep 3;
    start;

}
case "$1" in
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    'status')
        status
        ;;
    'restart')
        restart
        ;;
    *)
    echo "usage: $0 {start|stop|restart|status}"
    exit 1
        ;;
    esac

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM