Linux笔记··By/蜜汁炒酸奶

rc.local.service 找不到

根据 【Linux关闭swap】 编写 开机脚本 /etc/rc.local 后,执行 sudo systemctl enable rc-local 时提示如下异常:

Failed to restart rc.local.service: Unit rc.local.service not found.

解决方案:

之前执行的 systemctl 命令中的rc.local,需换成 rc-local,可能提示需安装。其具体过程如下

1. 链接文件 rc-local.service

# 将 /lib/systemd/system/rc-local.service 链接到 /etc/systemd/system/ 目录下面来


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

1
2
3
4
5

查看 /etc/systemd/system/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
1
2
3
4
5
6
7
8
9
10
11
12

此时再执行 sudo systemctl enable rc-local 将出现如下提示:

The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.

Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit’s
.wants/ or .requires/ directory.
• A unit’s purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, …).
• In case of template units, the unit is meant to be enabled with some
instance name specified.

2. 编辑文件 rc-local.service,新增配置

执行如下操作 sudo vi /etc/systemd/system/rc-local.service 新增:

[Install]
 WantedBy=multi-user.target
1
2

之后再执行 sudo systemctl enable rc-local 得到提示:

Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.

此时可成功只执行 sudo systemctl restart rc-local

预览
Loading comments...
0 条评论

暂无数据

example
预览