使用systemd作为特定用户运行时loggingstdout

考虑下面的test-echo.service

 [Unit] Description=Testing journalling of stdout [Service] ExecStart=/bin/echo hello world [Install] WantedBy=multi-user.target 

其预期结果如期在期刊上:

 $ sudo systemctl enable test-echo $ sudo systemctl start test-echo $ sudo journalctl -e -u test-echo > ... systemd[1]: Started Testing journalling of stdout. > ... echo[20178]: hello world $ sudo systemctl stop test-echo 

现在我在[Service]部分下添加User=ubuntuubuntu是一个现有的常规用户。

 $ sudo systemctl daemon-reload $ sudo systemctl start test-echo $ sudo journalctl -e -u test-echo > ... systemd[1]: Started Testing journalling of stdout. 

请注意,日志中现在缺less回显消息。 为什么是这样,我怎样才能让它出现?

我在Ubuntu 16.04上使用systemd 229。

journald目前无法在退出之前立即对进程的输出进行journald ,这对于像echo这样的非常短暂的进程尤其如此。 这是由于journald如何从进程' /proc获取某些信息(例如, _SYSTEMD_UNIT_COMM字段),在您的输出处理时可能不再存在。

你可以在GitHub和Bugzilla 上findbug报告。