chkconfig


chkconfig:
說明:

    用來設置服務的運行級信息,該設置並非立即啟動,或者禁用制定服務。

常用參數:

--add           增加所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啟動的敘述文件內增加相關數據。
--del            刪除所指定的系統服務,不再由chkconfig指令管理,並同時在系統啟動的敘述文件內刪除相關數據。

--level          <等級代號>  指定讀系統服務要在哪一個執行等級中開啟或關畢。

等級代號說明:
等級0表示:表示關機
等級1表示:單用戶模式
等級2表示:無網絡連接的多用戶命令行模式
等級3表示:有網絡連接的多用戶命令行模式
等級4表示:不可用
等級5表示:帶圖形界面的多用戶模式
等級6表示:重新啟動

--list [name]: 顯示所有運行級系統服務的運行狀態信息(on或off)。如果指定了name,那么只顯示指定的服務在不同運行級的狀態。

 使用范例:

1、列出所有服務

chkconfig --list

2、增加服務 rhythmk

chkconfig --add rhythmk

3、刪除服務 rhythmk

chkconfig --del rhythmk 

4、 設置 rhythmk 服務 在 2 3 4 5 運行基本下都是 on (開啟)狀態

chkconfig --level rhythmk 2345 on 

5、 列出 rhythmk 的 服務設置情況

chkconfig --list rhythmk

6、設置服務 rhythmk 所有運行等級下都是啟動 

chkconfig rhythmk on

拓展:  

  1>、新建shell文件 rhythmk ,保存路徑 /etc/init.d/ :

 1 #!/bin/bash
 2 # chkconfig: 2345 10 90 
 3 # description: rhythmk
 4 start() {
 5         echo "Starting"
 6 
 7 }
 8 
 9 stop() {
10           echo "Stop"
11 }
12 reload() {
13    echo "Reload"
14 }
15 
16 case "$1" in
17   start)
18         start
19         ;;
20   stop)
21         stop
22         ;;
23 
24   restart)
25         stop
26         start
27         ;;
28 
29   *)
30 echo $"Usage: $prog {start|stop|restart}"
31         RETVAL=2
32 esac

 

2>、為 shell 文件 rhythmk 添加 可以執行權限

cd /etc/init.d/
chmod u+x rhythmk

3>、測試 shell

./rhythmk start

service rhythmk start

備注:
需要添加如下注釋,否則提示 “service rhythmk does not support chkconfig”
# chkconfig: 2345 10 90
# description: rhythmk

注釋#chkconfig 中2345是默認啟動級別,10 90
10是啟動優先級,90是停止優先級

4>、配置rhythmk 開機啟動

 chkconfig  --add rhythmk

 

 


免責聲明!

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



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