systemd write log to file
Redirect
StandardOutput=file:/var/log/flume-ng/log1.log
StandardError=file:/var/log/flume-ng/log2.log
as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
Note that this way the whole log files contents will be overwritten each time service restarts.
Append
If you want to maintain file log between service restarts and just append new logged lines to it:
# Works only in systemd v240 and newer!
StandardOutput=append:/var/log/flume-ng/log1.log
StandardError=append:/var/log/flume-ng/log2.log
In case of systemd older than v240, you can use:
ExecStart=/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'
exec means that shell program will be substituted with my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.
Are there any code examples left?
New code examples in category Shell/Bash
-
Shell/Bash 2022-03-27 22:30:33 wise highlight ubuntu
-
Shell/Bash 2022-03-27 22:25:19 how to send a pull request in git
-
Shell/Bash 2022-03-27 21:55:06 how to open terminal in sublime text ubuntu
-
Shell/Bash 2022-03-27 21:25:19 how to switch branch
-
Shell/Bash 2022-03-27 21:20:25 python
-
Shell/Bash 2022-03-27 21:20:04 set user as admin gitlab
-
Shell/Bash 2022-03-27 21:10:09 apache2 mod_jk proxy to tomcat connector
-
Shell/Bash 2022-03-27 20:35:12 chown
-
Shell/Bash 2022-03-27 20:15:08 awk last match