【笔记】Chkconfig管理服务

前言

Linux上使用Chkconfig管理服务

查看所有使用Chkconf管理的服务

1
chkconfig --list

查看指定服务管理情况

<named>:服务名,通常以d结尾

1
chkconfig --list <named>

添加由chkconfig管理的脚本

1
chkconfig --add <named>

移除由chkconfig管理的脚本

1
chkconfig --del <named>

改变服务状态

1
2
3
chkconfig <named> on

chkconfig <named> off

修改自启状态

--level 5:指定读系统服务要在哪一个执行等级中开启或关毕,5为桌面启动时自启

1
2
3
chkconfig --level 5 <named> on

chkconfig --level 5 <named> off

创建由chkconfig管理的脚本

  • /etc/init.d目录下创建xxxd文件
  • 脚本编写前,要标注允许被chkconfig管理

chkconfig:允许被chkconfig管理,第一个数字表示第几个启动,第二个数字表示第几个关闭
decription:描述,介绍这是什么程序的启动脚本
processname:指定进程文件(可选)
config:指定配置文件(可选)
pidfile:指定pid文件(可选)

/etc/init.d/xxxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
#
# chkconfig: - 00 00
# decription: xxx script
# processname: xxxd
# config: xxx.conf
# pidfile: xxx.pid

start() {
...
}

stop() {
...
}

case $1 in
start)
start
;;
stop)
stop
;;
*)
echo "Usage :$0 {start|stop}"
;;
esac

完成

参考文献

哔哩哔哩——千锋教育网络安全学院
菜鸟笔记