Debian 8 带有开机自启动的 rc.local 文件。

Debian 9 和 10 则不带 rc.local 文件。

一、添加 rc.local.service

增加 systemd 服务

cd /etc/systemd/system
vi rc.local.service

键入以下内容,保存

[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
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

二、新建 rc.local 文件

cd /etc
vi rc.local

键入以下内容,保存

#!/bin/sh -e
#
# rc.local
#
# 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.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.



exit 0

三、添加权限并设置开机自启

重载新增加的服务

systemctl daemon-reload

设置 rc.local 的权限,并设置开机自启。

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