在 CentOS 8.X 中启用 rc-local 服务

在 CentOS 8.X 中启用 rc-local 服务

我试图在CentOS 8.1中启用rc.local,服务文件默认存在,但我无法启用它:

[root@localhost ~]# 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:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

有任何想法吗?

答案1

我认为这是一个特殊的单位,符合第 3 点:

3) 一个单元可以在需要时通过激活(套接字、路径、计时器、D-Bus、udev、脚本化的 systemctl 调用……)来启动。

所以你不systemctl enable这样做。您可以通过使rc.local文件可执行来启用它,就像在非 SystemD 系统上一样。

可以用 来验证systemctl cat rc-local。记笔记ConditionFileIsExecutable=/etc/rc.d/rc.local

因此,与平常一样rc.local,将命令放入/etc/rc.local(符号链接/etc/rc.d/rc.local)并通过 使文件可执行chmod +x,以在启动时启用/运行此“服务”。

相关内容