作为Systemd服务运行时,如何将输出管道传输到文件? [英] How to Pipe Output to a File When Running as a Systemd Service?

查看:257
本文介绍了作为Systemd服务运行时,如何将输出管道传输到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过管道将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/filename2>&1

尝试:

ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'

这篇关于作为Systemd服务运行时,如何将输出管道传输到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆