systemd / pystemd

A thin Cython-based wrapper on top of libsystemd, focused on exposing the dbus API via sd-bus in an automated and easy to consume way.
GNU Lesser General Public License v2.1
411 stars 36 forks source link

[Feature Request] Support user units #41

Closed Kunsi closed 4 years ago

Kunsi commented 4 years ago

I would like to integrate this into my i3pystatus config to show if redshift.service is active. However this Library does not seem to allow to check user services.

aleivag commented 4 years ago

hello!!... so we do have support for user units, but its kind of hidden... here is and example

import pystemd
from pystemd.dbuslib import DBus

In [12]: with DBus(user_mode=True) as bus, pystemd.systemd1.Unit("dotsync-poll.service", bus=bus) as service:
    ...:     print(service.ExecStart)
    ...:     
[(b'/usr/lib/dotsync/poll', [b'/usr/lib/dotsync/poll'], False, 1580064070114529, 11690243008440, 1580064080617836, 11690253511747, 2523869, 1, 0)]

you need to create a user dbus, and then pass it to the service...

there are things to support machine buffer and local ad-hoc sockets in case you are interested :D

hope this helps... and please let us know how it goes with the implementation!! :)

blooalien commented 4 years ago

Found this issue while seeking the exact same thing. Your response might be a good thing to copy somewhere into the readme/docs for others who also use user units.