如何允许用户使用 journalctl 查看用户特定的 systemd 服务日志?

Chr*_*rts 32 permissions systemd systemctl journalctl ubuntu-16.04

我在 Ubuntu 16.04 LTS 中运行用户级服务。例如,我的 test.service 位于~/.config/systemd/user/test.service.

我能够通过这样做来运行服务

systemctl --user start test.target
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用 读取其日志时journalctl,收到以下错误消息:

journalctl --user -u test.service
Hint: You are currently not seeing messages from other users and the system.
  Users in the 'systemd-journal' group can see all messages. Pass -q to
  turn off this notice.
No journal files were opened due to insufficient permissions.
Run Code Online (Sandbox Code Playgroud)

如何journalctl用于用户的特定单位?

小智 21

在较旧的 systemd 版本上,您必须使用journalctl --user --user-unit=SERVICENAME(在较新的版本上journalctl --user -u SERVICENAME可以正常工作)。

但是,这仅在Storageof[Journal]部分的指令/etc/systemd/journald.conf设置为persistent(而不是autoor volatile)时才有效。编辑完配置文件后重启,用户就可以看到日志了。

更多信息:https : //www.freedesktop.org/software/systemd/man/journald.conf.html https://lists.freedesktop.org/archives/systemd-devel/2016-October/037554.html

  • 将用户添加到 systemd-journal 组将是一种解决方法,但由于我的服务是用户服务,我不认为日志是首先生成的,因此允许我的用户查看所有其他日志不会反正有帮助。 (4认同)
  • 即使存储设置为易失性,“journalctl --user-unit SERVICENAME”也能正常工作。但是任何 `-u SERVICENAME`、`--user -u SERVICENAME` 或 `--user --user-unit SERVICENAME` 都不适用于易失性存储,它们都只是显示“无条目”。 (4认同)
  • 将用户添加到 systemd-journal 组是我需要的答案(来自该邮件列表链接)。 (2认同)