Debian9解决开机自启问题

由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的

并且默认情况下这个服务还是关闭的状态

1
2
3
4
5
6
root@debian9 ~ # systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: inactive (dead)

为了解决这个问题,我们需要手工添加一个 /etc/rc.local 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat <<EOF >/etc/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
EOF

然后赋予权限

1
chmod +x /etc/rc.local

接着启动 rc-local 服务

1
systemctl start rc-local

然后你就可以把需要开机启动的命令添加到 /etc/rc.local 文件,丢在 exit 0 前面即可.
重启以后试试是否生效了