作为Systemd服务运行时,如何将输出管道传输到文件? [英] How to Pipe Output to a File When Running as a Systemd Service?
问题描述
我无法通过管道将STDOUT&将程序作为systemd服务运行时,将STDERR转换为文件.我尝试将以下内容添加到.service
文件:
I'm having trouble piping the STDOUT & STDERR to a file when running a program as a systemd service. I've tried adding the following to the .service
file:
ExecStart=/apppath/appname > /filepath/filename 2>&1
但这不起作用.输出以/var/log/messages结尾,并且可以使用journalctl查看,但我想要一个单独的文件.
But this doesn't work. The output is ending up in /var/log/messages and is viewable using journalctl but I'd like a separate file.
我也尝试设置StdOutput=tty
,但是找不到将其重定向到文件的方法.
I've also tried setting StdOutput=tty
but can't find a way of redirecting this to a file.
任何帮助将不胜感激.
推荐答案
ExecStart =
ExecStart=
启动此服务时执行的命令及其参数.
Commands with their arguments that are executed when this service is started.
因此,systemd
使用参数>
,/filepath/filename
,2>&1
尝试:
ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'
这篇关于作为Systemd服务运行时,如何将输出管道传输到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!