page counter next up previous contents
Next: 開機過程的問題解決 Up: 開機流程與系統服務 Previous: daemon 與服務 (service)   Contents

開機啟動服務

  1. chkconfig指令
    [root@deyu ~]# chkconfig --help
    chkconfig version 1.3.47 - Copyright (C) 1997-2000 Red Hat, Inc.
    This may be freely redistributed under the terms of the GNU Public License.
    
    usage:   chkconfig [--list] [--type <type>] [name]
             chkconfig --add <name>
             chkconfig --del <name>
             chkconfig --override <name>
             chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
    
  2. 列出所有服務開機啟動狀態
    [root@deyu ~]# chkconfig --list
    httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    xinetd         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    ypbind         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    
    xinetd based services:
    	rsync:         	off
    	tftp:          	on
    
  3. 列出某一服務開機啟動狀態
    [root@deyu ~]# chkconfig --list httpd
    httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    
  4. 設定某一服務開機立即啟動
    [root@deyu ~]# chkconfig httpd on
    [root@deyu ~]# chkconfig --list httpd
    httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
  5. 設定某一服務某一層級開機時關閉或啟動
    [root@deyu ~]# chkconfig --level 2 httpd off
    [root@deyu ~]# chkconfig --list httpd
    httpd          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    

  6. 自訂服務
    1. 為何無法加入?
      [root@deyu ~]# vi /etc/init.d/myservice
      #!/bin/bash
      echo "chkconfig test"
      [root@deyu ~]# chkconfig --add myservice
      service myservice does not support chkconfig
      

    2. 加chkconfig的敘述,成功加入自訂服務。
      [root@deyu ~]# vi /etc/init.d/myservice
      #!/bin/bash
      # chkconfig: 35 91 81 <= 注意以下測試
      # description: only for test
      echo "chkconfig test"
      [root@deyu ~]# chkconfig --add myservice 
      [root@deyu ~]# chkconfig --list myservice 
      myservice      	0:off	1:off	2:off	3:on	4:off	5:on	6:off
      
      # run level 3及5啟動;/etc/rc.d/rc[35].d 當中啟動時,以91順位啟動,以81順位結束。
      [root@deyu ~]# ll /etc/rc.d/rc[35].d/*myservice*
      lrwxrwxrwx. 1 root root 19 Dec 26 09:28 /etc/rc.d/rc3.d/S91myservice -> ../init.d/myservice
      lrwxrwxrwx. 1 root root 19 Dec 26 09:28 /etc/rc.d/rc5.d/S91myservice -> ../init.d/myservice
      
      # run level 1關閉;/etc/rc.d/rc1.d 當中以81順位結束。
      [root@deyu ~]# ll /etc/rc.d/rc1.d/*myservice*
      lrwxrwxrwx. 1 root root 19 Dec 26 09:28 /etc/rc.d/rc1.d/K81myservice -> ../init.d/myservice
      
    3. 刪除自訂服務
      [root@deyu ~]# chkconfig myservice off
      [root@deyu ~]# chkconfig --list myservice 
      myservice      	0:off	1:off	2:off	3:off	4:off	5:off	6:off
      [root@deyu ~]# chkconfig --del myservice 
      [root@deyu ~]# chkconfig --list myservice 
      service myservice supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add myservice')
      [root@deyu ~]# rm -f /etc/init.d/myservice
      [root@deyu ~]# chkconfig --list myservice 
      error reading information on service myservice: No such file or directory
      



2015-04-13