ExecStart=/apppath/appname > /filepath/filename 2>&1
但这不起作用。输出最终以/var/log/log/消息最终使用,并且可以使用日记cttl查看,但我想要一个单独的文件。
我还尝试了设置StdOutput=tty
,但找不到将其重定向到文件的方法。
任何帮助将不胜感激。
systemd.service(5)
说:命令及其参数启动时执行。So,
systemd
用args,
/apppath/appname
,
>
/filepath/filename
运行
2>&1
try:
ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'
try:ExecStart=/usr/bin/sh -c "/apppath/appname > /filepath/filename 2>&1"
Execstart要求第一个参数是二进制论点(不例外),并且不允许管道或重定向。因此,使用execstart启动一个外壳,您可以在其中完成所有需要的花哨的事情。
man:systemd.exec
StandardOutput=
Controls where file descriptor 1 (stdout) of the executed processes is connected to. Takes one of inherit,
null, tty, journal, kmsg, journal+console, kmsg+console, file:path, append:path, truncate:path, socket or
fd:name.
The file:path option may be used to connect a specific file system object to standard output. The semantics
are similar to the same option of StandardInput=, see above. If path refers to a regular file on the
filesystem, it is opened (created if it doesn't exist yet) for writing at the beginning of the file, but
without truncating it. If standard input and output are directed to the same file path, it is opened only
once — for reading as well as writing — and duplicated. This is particularly useful when the specified path
refers to an AF_UNIX socket in the file system, as in that case only a single stream connection is created
for both input and output.
append:path is similar to file:path above, but it opens the file in append mode.