Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33876
  • 博文数量: 13
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-03 20:25
个人简介

30了还在编码

文章分类

全部博文(13)

文章存档

2015年(4)

2013年(8)

2012年(1)

我的朋友
最近访客

分类: LINUX

2013-03-05 23:00:34

【概要】

       chkconfig命令用于更新和查询系统Linux系统服务的运行级别信息

【语法】

  1. chkconfig --list [name]     
  2. chkconfig --add name        
  3. chkconfig --del name       
  4. chkconfig [--level levels] name     
  5. chkconfig [--level levels] name
【使用】

▼输出所有服务的启动信息

  1. # chkconfig --list
  2. syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  3. netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
  4. network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  5. pppoe 0:off 1:off 2:off 3:off 4:off 5:off 6:off
  6. avahi-daemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off
  7. snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
  8. postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  9. 省略

▼登录服务

  1. # chkconfig --add proftpd

▼删除服务

  1. # chkconfig --del proftpd
▼按执行等级开启/关闭服务。
  1. # chkconfig --level 2345 netfs off
  2. # chkconfig --level 2345 netfs on
△关于执行等级

  1.       等级0表示:表示关机
          等级1表示:单用户模式
          等级2表示:无网络连接的多用户命令行模式
          等级3表示:有网络连接的多用户命令行模式
          等级4表示:不可用
          等级5表示:带图形界面的多用户模式
          等级6表示:重新启动

【自作系统服务登录到chkconfig的方法】
有时候我们需要让自己写shell服务或者其他应用服务保持开机自启动的状态,这里简要介绍如果把自作的服务登录到chkconfig。

首先作为例子,我们做一个简单的shell,命名为test。

  1. #!/bin/sh
  2. #
  3. # /etc/rc.d/init.d/test
  4. #
  5. # Starts the test daemon(test version)
  6. #
  7. # chkconfig: 345 44 56
  8. # description: test

  9. case $1 in
  10. start)
  11.     echo "test service start!"
  12.     ;;
  13. stop)
  14.     echo "test service stop!"
  15.     ;;
  16. status)
  17.     echo "test service status!"
  18.     ;;
  19. *)
  20.     echo "Usage: test [start|stop|status]"
  21.      ;;
  22. esac
  23. exit 0
红字部分是重点。如果不定义[chkconfig:]和[description:]的话,自作的服务就无法被登录。

chkconfig: AAA BBB CCC
    AAA ???该脚本将在运行级别
    BBB ???启动优先级
    CCC ???停止优先级
description: 説明

上面的例子中,运行级别为3,4,5的时候ON,除外为OFF,另外启动级别为44,停止级别为56。

下一步将写好的shell复制到/etc/init.d,登录新的命令test。操作如下
  1. # chkconfig --add test
  2. # chkconfig --list | grep test
  3. test 0:off 1:off 2:off 3:on 4:on 5:on 6:off
  4. # cd /etc/rc.d
  5. # ls -l rc[0-6].d/*test                       查看test在各个运行级别下的
  6. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc0.d/K56test -> ../init.d/test
  7. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc1.d/K56test -> ../init.d/test
  8. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc2.d/K56test -> ../init.d/test
  9. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc3.d/S44test -> ../init.d/test
  10. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc4.d/S44test -> ../init.d/test
  11. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc5.d/S44test -> ../init.d/test
  12. lrwxrwxrwx 1 root root 14 2000-00-00 00:00 rc6.d/K56test -> ../init.d/test
最后测试一下test是否被正常登录了。
  1. # service test start
  2.   test service start!
  3. # service test stop
  4.   test service stop!
  5. # service test status
  6.   test service status!
  7. # service test
  8.   Usage: test [start|stop|status]
例子演习完毕,删掉它吧,看着闹心。
  1. # chkconfig --del test
  2. # chkconfig --list | grep test















阅读(1092) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~