journalctl Command Reference: Flags, Usage & CI Examples
journalctl reads and filters the systemd journal log.
journalctl queries the structured logs systemd collects from services and the kernel. On self-hosted runners it is the first stop when a managed service misbehaves.
Common flags and usage
- -u <unit>: show logs for one unit
- -f: follow new log lines (like tail -f)
- --since "10 min ago": filter by time
- -n <N>: show the last N lines
- -p err: filter by priority (e.g. error and worse)
- -b: show logs from the current boot only
Example
shell
systemctl is-active --quiet myservice \
|| journalctl -u myservice -n 200 --no-pagerIn CI
When a self-hosted-runner service fails to come up, dump journalctl -u <unit> -n 200 --no-pager so the failing logs land in the CI output. Add --no-pager so it does not block waiting for an interactive pager.
Key takeaways
- journalctl reads the systemd journal, filtered by unit, time, or priority.
- journalctl -u <unit> --no-pager surfaces a failed service log in CI.
- It only sees systemd-managed logs, so it needs systemd present.
Related guides
systemctl Command Reference: Flags, Usage & CI ExamplesReference for systemctl: start, status, is-active, enable, the no-systemd-in-containers caveat, and a CI exam…
service Command Reference: Usage & CI ExamplesReference for the service command: start, stop, status, --status-all, the SysV/init wrapper role, and a CI ex…
top Command Reference: Flags, Batch Mode & CI ExamplesReference for top: -b batch mode, -n, -o, -d, the non-interactive logging pattern, and a CI example that capt…