Debian 9-12 启用开机自动启动程序 /etc/rc.local
自从 Debian 9 开始,Debian 默认不带 /etc/rc.local 文件,所以我们需要手动创建它。
创建缺失的 /etc/rc.local
cat </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
EOFchmod +x /etc/rc.local
创建缺失的 rc.local 服务
Debian 12 可能没有默认的 rc.local 服务,我们需要手动创建它。
cat </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 是一个服务,通常用于在系统启动时运行一些自定义的脚本或命令
本文出自 蓝鹰博客,转载时请注明出处及相应链接。
本文永久链接: http://www.lanyingblog.com/blog/3199.html