SystemD 单元文件文档错误

SystemD 单元文件文档错误

我想创建一个 SystemD 单元文件,并使用文档选项引用我创建的文本文件。但是每次我使用该systemctl help test1.service命令(以 root 身份)时,都会出现错误。为了说明这个问题,我举了一个例子:

以下是我将在 SystemD Unit 中启用以进行测试的脚本:

[centos@localhost ~]$ cat ~/test.sh
#!/bin/sh
echo "hello"

以下是我将在 SystemD Unit 中引用的文档文件:

[centos@localhost ~]$ cat ~/test.txt

this is a piece of test documentation

这是系统 D 单元文件:

[centos@localhost ~]$ cat /etc/systemd/system/test1.service 

[Unit]
Description=Test
Documentation=file://localhost/home/centos/test.txt

[Service]
ExecStart=/home/centos/test.sh

[Install]
WantedBy=multi-user.target

现在激活我的单元文件,并尝试查看与该单元相关的文档:

[centos@localhost ~]$ sudo systemctl daemon-reload 
[centos@localhost ~]$ sudo systemctl restart test1.service 
[centos@localhost ~]$ sudo systemctl status test1.service 
● test1.service - Test
   Loaded: loaded (/etc/systemd/system/test1.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sun 2019-02-17 18:37:13 GMT; 6s ago
     Docs: file://localhost/home/centos/test.txt
  Process: 16036 ExecStart=/home/centos/test.sh (code=exited, status=0/SUCCESS)
 Main PID: 16036 (code=exited, status=0/SUCCESS)

Feb 17 18:37:13 localhost.localdomain systemd[1]: Started Test.
Feb 17 18:37:13 localhost.localdomain test.sh[16036]: hello

问题如下:

[centos@localhost ~]$ systemctl help test1.service 
Can't show: file://localhost/home/centos/test.txt

我最初以为这是的命名约定file。但阅读文档后,我应该能够使用(并测试过)这三种格式(每次重新启动systemd守护程序并重新启动服务):

file://localhost/home/centos/test.txt
file:///home/centos/test.txt
file:/home/centos/test.txt

但每次我尝试使用帮助命令查看我的设备的文档时,都会出现相同的错误systemd。为什么?

答案1

的实现systemctl help基本上是“如果它是一个 man uri 就显示它,否则说你不能显示它”:

        STRV_FOREACH(p, i->documentation)
                if (startswith(*p, "man:"))
                        show_man_page(*p + 4, false);
                else
                        log_info("Can't show: %s", *p);

(从 https://github.com/systemd/systemd/blob/master/src/systemctl/systemctl.c#L4643

相关内容