如何将 systemd 启动的服务输出重定向到文件?

如何将 systemd 启动的服务输出重定向到文件?

我刚开始玩普罗米修斯并将其安装为服务。

最初,我在一个屏幕上启动它并让它运行,但我想将它作为 systemd 管理的服务运行,因此想将它的所有输出重定向到一个日志文件ExecStart=/opt/prometheus/prometheus/prometheus &> /opt/prometheus/prometheus/prometheus.log导致错误,但如果我删除重定向,systemd 仍然会报告超时错误,但服务已启动并成功运行。不过我发现本文这是迄今为止我发现的第二好的事物,但这不是我想要实现的。

编辑:按要求提供错误消息

- Subject: Unit prometheus.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit prometheus.service has begun starting up.
Sep 04 09:14:13 prometheus prometheus[4036]: prometheus: error: unexpected >>
Sep 04 09:14:13 prometheus systemd[1]: prometheus.service: Control process exited, code=exited status=1
Sep 04 09:14:13 prometheus systemd[1]: Failed to start Prometheus monitoring system for monitoring system nodes and services.
-- Subject: Unit prometheus.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit prometheus.service has failed.
--
-- The result is failed.

相关内容