Created
August 10, 2021 13:36
-
-
Save timhughes/6b9460590d07f36c86267ad8d5a96fd8 to your computer and use it in GitHub Desktop.
python systemd dbus example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import pydbus | |
import logging | |
unit_name='sshd.service' | |
sysbus = pydbus.SystemBus() | |
systemd = sysbus.get('.systemd1') | |
unit = sysbus.get('.systemd1', systemd.GetUnit(unit_name)) | |
unit_state = unit.ActiveState | |
logging.warn("Unit %s: %s", unit_name, unit_state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment