Redirect the Output of systemd Service to a File

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:

 
 

 

posted @ 2023-05-20 04:43  MR__Wang  阅读(12)  评论(0编辑  收藏  举报