Linux/rc-local

Linux/rc-local

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 8

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

CentOS 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

/etc/rc.local 默认是指向 /etc/rc.d/rc.local 的符号链接。但 /etc/rc.d/rc.local 默认没有执行权限。

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


Last update: 2021-08-05 06:50:21 UTC