systemd 显然没有找到 .service 文件

systemd apparently not finding .service file

我已经为我们的 运行 作为守护程序的 foo 服务整理了一个 foo.service 文件。当我 运行 systemctl start foo(和 stop)时,服务 运行 很好,但是 systemtcl enable foo 结果是 Failed to issue method call: Invalid argument。单元文件放在 /etc/systemd/system/foo.service 中,权限为 0755。将 systemd 设置为调试并 运行ning 启用会得到

Looking for unit files in (highest priority first):`
    /etc/systemd/system
    /run/systemd/system
    /usr/local/lib/systemd/system
    /usr/lib/systemd/system
Looking for SysV init scripts in:
    /etc/rc.d/init.d
Looking for SysV rcN.d links in:
    /etc/rd.c
Failed to issue method call: Invalid argument

谷歌搜索,似乎 systemctl 没有找到 .service 文件。有什么办法可以验证吗?如果是这样,我该如何解决?关于什么可能是错误的任何其他想法?我可以启用更多调试吗?给出的调试信息并不能真正帮助我缩小问题范围。

foo.service 看起来像:

[Unit]
Description=Blah Blah Blah

[Service]
ExecStart=/usr/bar/doof/foo
Type=simple
PIDFile=/var/run/foo.pid

[Install]
WantedBy=multi-user.target,graphical.target

编辑:是的,我做了 运行 systemctl daemon-reload

错误是因为两个目标指定给 WantedBy。就这样提一下:

[Install]
WantedBy=multi-user.target

真不知道怎么给它指定两个目标。

来自 Google 的人:

  • sudo systemd-analyze verify NAME.service
  • 验证
  • 使用符号链接时,确保它使用绝对路径
  • 确保名称类似于 /etc/systemd/system/*.service
  • 更改后执行sudo systemctl daemon-reload

我的问题是文件是从 另一个分区 systemd do not support that.

建立符号链接的

Unit files have to reside on a partition that is mounted at the moment the host PID 1 is invoked. i.e. either on the root partition or some other partition that the initrd premounts.

我正在回答一个老问题,因为这是谷歌搜索该问题时的最佳结果,可能会对某人有所帮助

我在 google 上找到这个问题,搜索“找不到 systemctl 单元”

在我的例子中,我通过 podman 生成了一个 *.service 文件,无论我做什么,systemctl 都找不到该服务文件。

解决方案是检查 selinux 并设置正确的标签。示例:

/sbin/restorecon -v /etc/systemd/system/container_httpd.service

我在使用 Podman 生成 systemd 单元文件时 运行 遇到这个错误。

错误发生是因为 selinux 阻止文件被正确读取。我发现有两种解决方案。

  1. 使用 cd /etc/systemd/system 将您的目录设置为单元文件的 systemd 服务位置。然后在这里直接使用podman generate创建文件。这似乎被 selinux 毫无问题地接受了。

  2. podman generate生成systemd单元文件并将文件复制到/etc/systemd/system。然后,您需要 运行 /sbin/restorecon -v /etc/systemd/system/container-<your container name>.service 让 selinux 重置该文件的安全上下文。