寫一個測試服務腳本

寫一個測試服務腳本

  1. 測試腳本放在 /etc/init.d/ 目錄下
  2. 應該加有執行權限
  3. 腳本內容應該有以下行
    1. # chkconfig: 運行級別 啓動順序編號 關閉順序編號
    2. # description: 
  4. 加入開機自啓動列表,會生成相應的軟連接
  5. 用 service 命令執行啓動關閉重啓等操做
  6. 舉例說明
    1. vim /etc/init.d/testsrv
    2. #!/bin/bash
      #
      # chkconfig: - 98 4
      # description: This is test script.
      .  /etc/init.d/functions
      
      start(){
      	touch /var/lock/subsys/testsrv
      	action "start testsrv"
      	
      }
      stop(){
      	rm -f /var/lock/subsys/testsrv
      	action "stopping testsrv"
      }
      status(){
      	[ -f /var/lock/subsys/testsrv ] && echo  "testsrv is running" || echo "testsrv is stopped" 
      }
      restart(){
      	stop
      	start	
      }
      case "$1" in
      start)
      	start
      	;;
      stop)
      	stop
      	;;
      restart)
      	restart
      	;;
      status)
      	status
      	;;
      *)
      	echo "Usage: testsrv {start|stop|status|restart}"
      	;;
      esac

       

    3. chmod +x  /etc/init.d/testsrvvim

    4. chkconfig --add testsrvbash

    5. chkconfig --level 123456 testsrv on函數

模擬故障

  1. 若是在腳本testsrv裏的start函數里加上 sleep=10000
  2. 開機時系統會自動啓動 testsrv,則會等待好久
  3. 解決辦法
    1. 進入單用戶模式,因爲單用戶模式也開機會啓動 testsrv,可要等待好久
    2. 重啓 按任意鍵 更改內核參數輸入a 在這一行的末尾加上 init=/bin/bash
      1. mount -o remount,rw /
      2. chkconfig --level 123456 testsrv off
      3. 重啓
相關文章
相關標籤/搜索