演示问题的简化示例是
#include <stdio.h>
int main(void)
{
printf("foon");
fflush(stdout);
getchar();
return 0;
}
(虽然它不是特定于编程语言的 - 我发现问题的原始应用程序是在 Go 中(。
如果它已编译并由以下单元运行:
[Unit]
Description=description
After=network.target
[Service]
ExecStart=/path/to/binary
[Install]
WantedBy=multi-user.target
然后systemctl restart
journald
在大多数情况下不会得到foon
输出,而syslog
成功地将其写到/var/log/syslog
。
下面是服务的journald
输出示例:
May 18 08:30:38 hostname systemd[1]: Stopped servicename
May 18 08:30:38 hostname systemd[1]: Started servicename
May 18 08:30:38 hostname systemd[1]: Stopped servicename
May 18 08:30:38 hostname systemd[1]: Started servicename
May 18 08:30:38 hostname servicename[7701]: foo
May 18 08:30:41 hostname systemd[1]: Stopped servicename
May 18 08:30:41 hostname systemd[1]: Started servicename
May 18 08:30:46 hostname systemd[1]: Stopped servicename
May 18 08:30:46 hostname systemd[1]: Started servicename
然后是/var/log/syslog
的相应部分:
May 18 08:30:38 hostname systemd[1]: Stopped servicename.
May 18 08:30:38 hostname systemd[1]: Started servicename.
May 18 08:30:38 hostname servicename[7682]: foo
May 18 08:30:38 hostname systemd[1]: Stopped servicename.
May 18 08:30:38 hostname systemd[1]: Started servicename.
May 18 08:30:38 hostname servicename[7701]: foo
May 18 08:30:41 hostname systemd[1]: Stopped servicename.
May 18 08:30:41 hostname systemd[1]: Started servicename.
May 18 08:30:41 hostname servicename[7720]: foo
May 18 08:30:46 hostname systemd[1]: Stopped servicename.
May 18 08:30:46 hostname systemd[1]: Started servicename.
May 18 08:30:46 hostname servicename[7739]: foo
有什么方法可以保证日记收到stdout
,如果有的话?
TLDR,这是一个已知问题。
我在systemd-devel邮件列表中问了同样的问题,并得到了有关报告问题的回复。