Skip to content

A way to subscribe to single unit state changes or to unit property changes #507

@NotSoFancyName

Description

@NotSoFancyName

I am trying to do some unit synchronization and I need to wait until the unit finishes deactivating . It is possible to do with a SubscriptionSet or with adaptation of SubscribeUnitsCustomContext, but both will result in polling the ListUnitsContext with some interval which seems like an overkill to me.

While exploring the code I have found this:

// SubscribeContext starts listening for dbus events for all of the units in the set.
// Returns channels identical to conn.SubscribeUnits.
func (s *SubscriptionSet) SubscribeContext(ctx context.Context) (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustomContext(ctx, time.Second, 0,
mismatchUnitStatus,

It seems there used to be a plan 8 years ago for the units in the SubscriptionSet to use PropertiesChanged signal for individaul units if I understand correctly.

This is already being done but for all units in Subscribe method

// explicitly call Unsubscribe().
func (c *Conn) Subscribe() error {
c.sigconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
"type='signal',interface='org.freedesktop.systemd1.Manager',member='UnitNew'")
c.sigconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
"type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'")
return c.sigobj.Call("org.freedesktop.systemd1.Manager.Subscribe", 0).Store()
}

and you could use this functionality by SetPropertiesSubscriber and SetSubStateSubscriber but one will updates for all units.

I wonder if it is possible and makes sense to do a feature to be able to subscribe for propertuies change for individual unit.

It is possible add unit path= to the subscribe D-Bus call to get the updates only on that unit but that will interfere with Subscribe if it is to be called later at some point.

Let me know what you think and we glad to help if it makes sense to have something like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions