chkconfig

本文详细介绍了Linux系统中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

 

 

转载于:https://www.cnblogs.com/rhythmK/p/4895030.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值