Você pode se conectar ao sinal PropertiesChanged em cada unidade que é emitida sempre que uma propriedade de uma unidade é alterada. A propriedade ActiveState
contains a state value that reflects whether the unit is currently active or not. The following states are currently defined: active, reloading, inactive, failed, activating, deactivating. active indicates that unit is active (obviously...). reloading indicates that the unit is active and currently reloading its configuration. inactive indicates that it is inactive and the previous run was successful or no previous run has taken place yet. failed indicates that it is inactive and the previous run was not successful (more information about the reason for this is available on the unit type specific interfaces, for example for services in the Result property, see below). activating indicates that the unit has previously been inactive but is currently in the process of entering an active state. Conversely deactivating indicates that the unit is currently in the process of deactivation.
(do systemd dbus docs ).
Para obter uma lista inicial de unidades, você pode usar o método ListUnits
e assinar os sinais UnitNew
e UnitRemoved
para ser notificado quando as unidades forem adicionadas / removidas.
Existem vários projetos existentes que já usam isso, incluindo systemd_mon e sagbescheid .