在使用较新版本的Ubuntu/Debian系统时,原来写入/etc/rc.local或者/etc/rc.d/rc.local文件中的开机命令不执行了?
Ubuntu 16.04以后,默认进程启动管理已经切换至systemd,不再使用init.d。
如果想和之前一样使用rc.local设置开机自启动,可以通过以下步骤
修改rc-local.service#
我们可以发现,/lib/systemd/system/目录下存在一个rc-local.service,但缺少Install信息,系统就不认为他是个systemd服务。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| cat > /etc/systemd/system/rc-local.service <<EOF
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
EOF
|
加入所需启动的服务即可,记得权限
chmod +x /etc/rc.local
启动rc-local服务#
1
2
3
| systemctl daemon-reload
systemctl start rc-local
systemctl enable rc-local
|