Debian 9-12 重新启用 /etc/rc.local
自从 Debian 9 开始,Debian 默认不带 /etc/rc.local
文件,所以我们需要手动创建它。
创建缺失的 /etc/rc.local
cat <<EOF >/etc/rc.local
#!/bin/sh -e
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
exit 0
EOF
chmod +x /etc/rc.local
创建缺失的 rc.local 服务
Debian 12 可能没有默认的 rc.local 服务,我们需要手动创建它。
cat <<EOF >/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
EOF
启用并立即启动服务
systemctl enable --now rc-local
执行后,可能回显 The unit files have no installation config
类似的警告,无视即可。命令意义如下:
systemctl
是 Systemd 的主命令,用于管理系统和服务
enable
是一个选项,用于设置服务在系统启动时自动运行
--now
是一个选项,用于立即启动服务,而不是等到下次系统启动
rc-local
是一个服务,通常用于在系统启动时运行一些自定义的脚本或命令