service
,顾名思义,是用于对系统服务进行管理的命令。
Basically, it’s a shell script! vi
it!
Besides, chkconfig
is a closely related command.
CentOS中的介绍:
|
|
[TOC]
service命令
service network start
就相当于/etc/init.d/network start
。
-
An example of service command:
12service netconsoleUsage: /etc/init.d/netconsole {start|stop|status|restart|condrestart}Comman used option include “start|stop|status|restart”
-
An example of init service script:
123456789101112case "$1" instart)do start-thing;;;stop)do stop-thing;;;restart)do restart-thing;;;...esac
chkconfig命令
service与chkconfig的关系归纳为:[1]
先要注册成为系统服务(即service可以调用),然后才能使用chkconfig控制运行级别。
service是chkconfig的前提条件。
注意:谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了/etc/rc*.d
中的符号连接。[2]
-
chkconfig --list
If you want to list systemd services use ‘systemctl list-unit-files’. -
chkconfig --add/del SERVICE
-
chkconfig SERVICE on/off
是否开机就执行 -
chkconfig --level SERVICE 3456
只在3456级别下运行该SERVICE
(/etc/rc*.d
下)S开始的文件向脚本传递start参数
K开始的文件向脚本传递stop参数
K/S后面的数字代表开机启动脚本中的启动顺序,数组越大启动越晚。[2] -
相应级别的文件在
/etc/rc*.d
之下12ls /etc/rc*.d -d/etc/rc.d /etc/rc0.d /etc/rc1.d /etc/rc2.d /etc/rc3.d /etc/rc4.d /etc/rc5.d /etc/rc6.d -
PS:
/etc/rc.d/rc*.d/
下的文件均为符号链接,最终绝大部分都是都是链接到/etc/rc.d/init.d
下面。/etc/rc.d/init.d
目录下面的都是开启启动脚本文件,用来启动相应的程序。 -
PPS: 开机顺序
硬件自检 -> 初始化启动bootloade -> 加载内核 -> 初始化硬件 -> 加载根文件系统 -> 加载驱动 -> 启动一个init用户级程序 -
PPPS: 上面两次加载硬件,是因为驱动分成两种:[3]
1.随内核加载的驱动,一般是中断控制器,串口,定时器,时钟,各种总线等;这种驱动的初始化函数一般会放到一个特殊的初始化段中,在内核初始化时调用;
2.编译成模块的驱动,在内核初始化完成,也就是初始线程创建完成,出现shell时,根据应用程序的需要或者脚本按需加载。