systemd显然没有找到.service文件

use*_*510 9 systemd

我为我们的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 give

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
Run Code Online (Sandbox Code Playgroud)

谷歌搜索似乎没有找到.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
Run Code Online (Sandbox Code Playgroud)

编辑:是的,我确实跑了systemctl daemon-reload.

小智 26

我通过谷歌发现了这个问题,搜索“systemctl unit not found”

就我而言,我通过 podman 生成了一个 *.service 文件,无论我做什么,systemctl 都找不到该服务文件。

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

/sbin/restorecon -v /etc/systemd/system/container_httpd.service
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!这对我来说是这样的。您能详细说明一下它到底有什么作用吗? (2认同)

Mar*_*ark 16

对于谷歌的人:

  • 验证 sudo systemd-analyze verify NAME.service
  • 使用符号链接时,请确保它使用绝对路径
  • 确保名称是这样的 /etc/systemd/system/*.service
  • sudo systemctl daemon-reload改变后做

  • 对我来说,我在做软链接(`ln -s ... ...`)。我做了硬链接(`ln ... ...`)并且它起作用了 (4认同)
  • @AnandUndavia 使用硬链接时,您应该会收到错误:`*.service 不是符号链接,忽略。`。 (2认同)

Asa*_*han 8

确保如果您将单元放入.config/systemd/user/*.service您运行命令的用户文件夹中

systemd --user <command>
Run Code Online (Sandbox Code Playgroud)

(注意--user


M4v*_*r1k 7

就我而言,问题是文件是从另一个分区进行符号链接的,而systemd不支持该链接。

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.

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