Linux/rc-local

Linux/rc-local

Debian 10 / 11

默认无 rc.local 但是可以轻易启用。

touch /etc/rc.local
chmod +x /etc/rc.local
systemctl daemon-reload
systemctl start rc-local

注意 systemctl start rc-local 会直接执行 /etc/rc.local 一次并将其标记为 "Active"(如果 exit code 为 0)或 "Failure" (如果 exit code 不为 0)。

ubuntu 20.04

vim /etc/systemd/system/rc-local.service

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

chmod +x /etc/rc.local
systemctl enable rc-local

CentOS 7 / CentOS 8

vi /usr/lib/systemd/system/rc-local.service

CentOS 7 / 8 里这个文件默认存在但缺少 [install] 块。在文件的末尾加上 [Install] 块后的文件内容:

[Unit]
Description=/etc/rc.d/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

Cent OS 8 里/etc/rc.local 默认是指向 /etc/rc.d/rc.local 的符号链接;但 /etc/rc.d/rc.local 默认没有执行权限。Cent OS 7 里默认没有 /etc/rc.local 文件,需要手工创建。

touch /etc/rc.d/rc.local
chmod a+x /etc/rc.d/rc.local
systemctl enable rc-local


Last update: 2022-04-15 03:29:47 UTC