Redirect the Output of systemd Service to a File

发布时间 2023-05-20 04:47:22作者: MR__Wang

By default stdout and stderr of a systemd unit are sent to syslog.

以filebeat service 为例:

 

[Unit]
Description=filebeat
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=on-failure
RestartSec=1
ExecStart=/data/filebeat/filebeat -e -c /data/filebeat/filebeat.yml
StandardOutput=append:/var/log/filebeat/filebeat.log
StandardError=append:/var/log/filebeat/filebeat.log

[Install]
WantedBy=multi-user.target

  

Now, we can watch the file for our service’s stdout and stderr: