Stop Scraping systemctl Output: Practical busctl on Linux
Описание и применение
Скрипты, использующие busctl, заменяют нестабильный парсинг вывода systemctl, обеспечивая типизированные, JSON‑подобные данные о состоянии системных юнитов.
Задача
Relying on parsing systemctl output is fragile due to column changes, locale variations, and container differences.
Результат
Scripts using busctl replace fragile text scraping, yielding stable, typed, JSON‑friendly systemd state queries.
Рабочий процесс
- Verify busctl version and capabilities (systemd 209+).
- List acquired, unique, and activatable bus names with busctl list.
- Inspect object trees with busctl tree and busctl introspect.
- Retrieve properties via busctl get-property, optionally using -j for JSON output.
- Resolve unit paths with busctl call Manager GetUnit and then query unit properties.
- Make method calls with busctl call, providing the correct D‑Bus signature.
- Use --user, --machine, or --capsule flags to target specific buses.
- Combine commands in scripts to replace systemctl status parsing.
- Validate outputs against expected JSON or typed values.
- Iterate and adjust scripts as systemd evolves.
Доказательства
busctl talks to the same D‑Bus APIs those tools already use. You get typed method calls, property reads, object trees, live monitors, and JSON-friendly output without inventing a parser for human-oriented CLI text.
Typical result: s "systemd-journald.service" s "Journal Service" s "loaded" s "active" s "running" u 331
- Дата записи: 2026-10-05T06:40:57.752Z