2

Something I've been wondering is if it's possible to get systemd to start tailing a log file when a unit is brought up, and to send that data into the system journal.

For the sake of discussion, let's say this program logs to a plain text file, and not to stdout. If I had to give an example, a Minecraft server would work.

I know of systemd-cat, but this is just a third party app like logger that doesn't tie into the unit system.

  • Maybe you can get the program to log to a named pipe and arrange for systemd to systemd-cat that named pipe? – Gilles Jan 13 '17 at 19:04
2

You could try this in your service unit file:

ExecStartPost=/bin/sh -c 'tail -f /path/to/log | systemd-cat'

It will be somewhat more fragile then the recommended pattern of logging to STDOUT because if the log file is rotated tail won't necessarily be connected the file descriptor again until the service restarted.

There is no built-in function to follow a log file that I'm aware. This is something other logging systems like rsyslog can do.

  • Is it smart enough to kill off the tail when the service is stopped? – Mikey T.K. Jan 13 '17 at 16:48
  • Build a simple hello-world unit file and check! – Mark Stosberg Jan 13 '17 at 16:56
  • 1
    tail's -F follows the file by path name instead of my inode id – ThorSummoner Aug 2 '17 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.