Mic*_*B76 32 linux stdout fedora stderr systemd
在将程序作为systemd服务运行时,我无法将STDOUT和STDERR传送到文件.我已经尝试将以下内容添加到.service
文件中:
ExecStart=/apppath/appname > /filepath/filename 2>&1
Run Code Online (Sandbox Code Playgroud)
但这不起作用.输出结果在/ var/log/messages中,可以使用journalctl查看,但我想要一个单独的文件.
我也试过设置,StdOutput=tty
但找不到将其重定向到文件的方法.
任何帮助,将不胜感激.
Evg*_*gin 46
ExecStart =
具有在启动此服务时执行的参数的命令.
因此,systemd
运行您/apppath/appname
与ARGS >
,/filepath/filename
,2>&1
尝试:
ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'
Run Code Online (Sandbox Code Playgroud)
尝试:
ExecStart=/usr/bin/sh -c "/apppath/appname > /filepath/filename 2>&1"
Run Code Online (Sandbox Code Playgroud)
ExecStart要求第一个参数为二进制(无例外),并且不允许管道或重定向。因此,使用ExecStart启动外壳程序,您可以在其中执行所有需要的操作。