After pip install pydbus use the following snippets for logs:
from systemd import journal
j = journal.Reader()
j.this_boot()
j.add_match(_SYSTEMD_UNIT="nginx.service")
for entry in j:
print(entry["MESSAGE"])
And for systemctl:
from pydbus import SystemBus
bus = SystemBus()
systemd = bus.get(".systemd1")
# Start a service
systemd.StartUnit("nginx.service", "replace")
# Get unit state
unit = bus.get(".systemd1", "/org/freedesktop/systemd1/unit/nginx_2eservice")
print(unit.ActiveState)
After
pip install pydbususe the following snippets for logs:And for systemctl: