今天一个同事告诉我遇到了一个问题:有一系列的sh和golang写的脚本,相互之间是通过stdout传递结果,在手工调用的时候工作良好,但是在托管给systemd的时候却不工作。怀疑是systemd截取了stdout,导致程序失败。
这个怀疑不无道理,因为在systemd的配置文件中有个很可以的配置项: StandardOutput=journey, 顺便贴出来官网对这个字段的解释:
StandardOutput=
Controls where file descriptor 1 (STDOUT) of the executed processes is connected to. Takes one of inherit
, null
, tty
, journal
, syslog
, kmsg
, journal+console
, syslog+console
, kmsg+console
, file:
, path
socket
or fd:
.name
inherit
duplicates the file descriptor of standard input for standard output.
null
connects standard output to /dev/null
, i.e. everything written to it will be lost.
tty
connects standard output to a tty (as configured via TTYPath=
, see below). If the TTY is used for output only, the executed process will not become the controlling process of the terminal, and will not fail or wait for other processes to release the terminal.
journal
connects standard output with the journal which is accessible via