chkconfig命令

.chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

在linux中服务以Shell脚本的形式提供,位于/etc/init.d目录下。

使用语法:
chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]

--level<等级代号>  指定读系统服务要在哪一个执行等级中开启或关毕。
      等级0表示:表示关机
      等级1表示:单用户模式
      等级2表示:无网络连接的多用户命令行模式
      等级3表示:有网络连接的多用户命令行模式
      等级4表示:不可用
      等级5表示:带图形界面的多用户模式
      等级6表示:重新启动

举例:

显示所有服务(包含各个等级状态)

chkconfig --list

添加|删除 tomcat服务

chkconfig --add|del tomcat

--设置tomcat服务在2、3、4等级为on,即达到开机自启动的目的

chkconfig tomcat on

--设置tomcat服务在2、3等级为on

chkconfig --level 23 tomcat on

自定义一个新服务需要注意:

1、脚本文件位于/etc/init.d目录下

2、shell脚本前几行的编写规范:

#!/bin/sh
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.

 简易版:   

#!/bin/sh
# chkconfig: 2345 90 60
# description: tomcat start service

 其中,2345为等级,90为启动优先级,60位关闭优先级。如果没有等级,可用-代替(# chkconfig: - 30 60)。

猜你喜欢

转载自hengdu.iteye.com/blog/2394683
今日推荐