【问题标题】:systemd apparently not finding .service filesystemd 显然没有找到 .service 文件
【发布时间】:2016-04-02 18:43:44
【问题描述】:

我已经为作为守护进程运行的 foo 服务整理了一个 foo.service 文件。当我运行systemctl start foo(和stop)时,服务运行良好,但是 systemtcl enable foo 导致 Failed to issue method call: Invalid argument。单元文件放在/etc/systemd/system/foo.service,权限为0755。将systemd设置为debug并运行enable给出了

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

【问题讨论】:

  • 在添加或更改 foo.service 文件后,您是否运行过systemctl daemon-reload
  • 是的,我确实运行了 daemon-reload

标签: systemd


【解决方案1】:

对于来自 Google 的人:

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

【讨论】:

  • 对我来说,我在做软链接 (ln -s ... ...)。我做了硬链接 (ln ... ...) 并且成功了
  • @AnandUndavia 你应该得到一个错误:*.service is not a symlink, ignoring. 使用硬链接时。
【解决方案2】:

我的问题是文件是从另一个分区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.

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

【讨论】:

    【解决方案3】:

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

    [Install]
    WantedBy=multi-user.target
    

    我真的不知道我们如何为它指定两个目标。

    【讨论】:

    • 多个目标以空格分隔,而不是逗号分隔。
    • WantedBy 选项可以多次使用,或者可以给出以空格分隔的单位名称列表。所以这个答案是正确的。
    【解决方案4】:

    我在谷歌上找到了这个问题,搜索“systemctl unit not found”

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      相关资源
      最近更新 更多