Skip to content

Instantly share code, notes, and snippets.

@timhughes
Created August 10, 2021 13:36
Show Gist options
  • Save timhughes/6b9460590d07f36c86267ad8d5a96fd8 to your computer and use it in GitHub Desktop.
Save timhughes/6b9460590d07f36c86267ad8d5a96fd8 to your computer and use it in GitHub Desktop.
python systemd dbus example
#! /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