如何在 Redhat、Centos 中更改 Linux init 脚本的启动顺序

如何在 Redhat、Centos 中更改 Linux init 脚本的启动顺序

从这个改变 如何更改 Linux 服务启动/引导顺序?改变符号链接的值显然会改变启动顺序。

在 Debian 衍生产品中我们使用

update-rc.d apache2 默认值 20 80

在 Centos/Redhat 中是否有类似的命令?

如果是的话那是什么?

并且初始化脚本头中应该进行哪些可能的更改?

注意:我应该使用 init 系统(而不是任何 systemd 或 upstart)

答案1

另一种方法是直接更改服务初始化脚本中以 开头的行# chkconfig:。这在chkconfig(8)请参阅手册页。

运行级别文件

每个应由 chkconfig 管理的服务都需要在其 init.d 脚本中添加两行或更多注释行。第一行告诉 chkconfig 默认情况下应在哪些运行级别启动服务,以及启动和停止优先级。如果默认情况下不应在任何运行级别启动服务,则应使用 - 代替运行级别列表。第二行包含服务的描述,可以使用反斜杠续写扩展到多行。

例如,random.init 有以下三行:

# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
#              higher quality random number generation.

这表示随机脚本应在级别 2、3、4 和 5 中启动,其启动优先级应为 20,其停止优先级应为 80。您应该能够弄清楚描述的内容; \ 使行继续。行前面的额外空格将被忽略。

更改脚本后,如果您需要chkconfig以 root 身份运行带有reset该服务选项的命令。使用“reset”,chkconfig 将自动在配置的运行级别中创建具有给定优先级的启动/停止符号链接。

答案2

您可以手动重命名 /etc/rcX.d 目录中的符号链接来更改启动顺序。

UPD:在 RHEL / CentOS 下,您可以使用名为 ntsysv 或 chkconfig 的命令。

答案3

我想为以上答案添加更多细节

为了启动脚本,特别是在 centos 中,没有这样的替代方案

update-rc.d 

在 Debain,

最简单的方法是更改​​脚本手动如此处所述以及来自 /etc/init.d/postfix 的代码

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
#
# Based on startup script from Simon J Mudd <[email protected]>
# 25/02/99: Mostly s/sendmail/postfix/g by John A. Martin <[email protected]>
# 23/11/00: Changes & suggestions by Ajay Ramaswamy <[email protected]>
# 20/01/01: Changes to fall in line with RedHat 7.0 style
# 23/02/01: Fix a few untidy problems with help from Daniel Roesen.

### BEGIN INIT INFO
# Provides: postfix MTA
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop postfix
# Description: Postfix is a Mail Transport Agent, which is the program that
#              moves mail from one machine to another.
### END INIT INFO

相关内容