I want to watch output from a
systemd service on CentOS as if I have started this service from console. Yes, I can see output with
journalctl, but it doesn't scroll to the bottom automatically. So how can I watch live output from service?
journalctl -f -u mystuff.service
It's in the manual:
Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.
Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN. If a pattern is specified, a list of unit names found in the journal is compared with the specified pattern and all that match are used. For each unit name, a match is added for messages from the unit ("_SYSTEMD_UNIT=UNIT"), along with additional matches for messages from systemd and messages about coredumps for the specified unit.
This parameter can be specified multiple times.
To add to @don_crissti’s answer, if you want to see just the output of that service, with nothing else, you can use this:
journalctl -f -o cat _SYSTEMD_UNIT=mystuff.service
-o cat selects an output format that omits additional information (such as timestamps), and the use of
_SYSTEMD_UNIT instead of
-u means that messages related to the service, but not printed by it (e. g. start/stop messages or core dumps) won’t be selected.
Note that the journal splits whatever it receives from a service via
StandardOutput=journal into log records at newline and
NUL characters, so if your service prints output without a terminating newline or
NUL character for a while, this output still won’t be quite live.