Ubuntu1804改用systemd来管理系统后,rc-local服务默认不再开启,记录一下如何开启这个服务

首先检查 /etc/systemd/system/rc-local.service文件是否存在,如果不存在,则创建这个文件

sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

然后编辑 sudo vim /etc/systemd/system/rc-local.service文件,添加Install节点

[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
Alias=rc-local.service

最后创建一下开机需要执行的 rc.local文件,sudo vim /etc/rc.local*,这里添加一个开机输出一个文件的测试

#!/bin/bash
echo 'hello world' > /tmp/hello.txt

最后使用systemd来启动开机执行

sudo systemctl enable rc-local