Closed docent-net closed 4 years ago
Hello!!!...
First of all, thanks for using pystemd, and more importantly, doing propper research on it... i should document this behaviors, but i'm probably the second most lazy developer in the world (and i'm too lazy to find out who is the first one)..
your issue, i believe, is that you did not start the dbus when you create it. You see, in the issue you referenced, the example say:
In [12]: with DBus(user_mode=True) as bus, pystemd.systemd1.Unit("dotsync-poll.service", bus=bus) as service:
...: print(service.ExecStart)
the __enter__
method on the DBus object https://github.com/facebookincubator/pystemd/blob/master/pystemd/dbuslib.pyx#L284-L286 calls self.open(). that's the thing you are missing, so
Welcome to pystemd 0.8.dev interactive shell for python 3.7.5+ (default, Jan 24 2020, 11:19:43)
[GCC 7.x 20200121 (Facebook) 8.x].
In [1]: import pystemd
...: from pystemd.dbuslib import DBus
In [2]: dbus = DBus(user_mode=True)
In [4]: pystemd.systemd1.Unit("dotsync-poll.service", bus=dbus, _autoload=True)
---------------------------------------------------------------------------
DBusBaseError Traceback (most recent call last)
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/examples/shell.py in <module>
----> 1 pystemd.systemd1.Unit("dotsync-poll.service", bus=dbus, _autoload=True)
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/systemd1/unit.py in __init__(self, external_id, bus, _autoload)
21 path=path,
22 bus=bus,
---> 23 _autoload=_autoload,
24 )
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/base.py in __init__(self, destination, path, bus, _autoload)
26
27 if _autoload:
---> 28 self.load()
29
30 def __enter__(self):
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/base.py in load(self, force)
87 return
88
---> 89 unit_xml = self.get_introspect_xml()
90 decoded_destination = self.destination.decode()
91
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/base.py in get_introspect_xml(self)
78 b"org.freedesktop.DBus.Introspectable",
79 b"Introspect",
---> 80 [],
81 ).body
82 )
/data/users/aleivag/fbsource/fbcode/buck-out/dev/gen/libfb/py/pystemd/pystemd-shell#link-tree/pystemd/dbuslib.pyx in pystemd.dbuslib.DBus.call_method()
DBusBaseError: [err -107]: Could not create DBus method
This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.
In [5]: dbus = DBus(user_mode=True)
In [6]: dbus.__enter__()
Out[6]: <pystemd.dbuslib.DBus at 0x7ff456c068a0>
In [7]: e = _
In [8]: pystemd.systemd1.Unit("dotsync-poll.service", bus=e, _autoload=True)
Out[8]: <pystemd.systemd1.unit.Unit at 0x7ff456c138d0>
or
In [9]: dbus = DBus(user_mode=True)
In [10]: dbus.open()
In [11]: pystemd.systemd1.Unit("dotsync-poll.service", bus=dbus, _autoload=True)
Out[11]: <pystemd.systemd1.unit.Unit at 0x7ff456a80810>
but still... you wanna use the with
context methods.
Hi Alvaro!
Not using a context manager makes me even lazier I think XD
Thanks for your help and explanation. Yeah, I didn't notice the enter method and what it does.
And also thanks for great talk during 2018 All Systems Go. One of my favourites from that conference :)
Hi,
I'm running a user service [1] defined in ~/.config/systemd/user/stub.service I'd like to manage this service via pystemd. There is no documentation for this kind of use, however I found an issue related to it where I read that pystemd should just work fine with user services.
So I tried something very simple:
And I receive:
My setup is Fedora 31, SELinux in permissive mode, cgroups v1, and this service is active:
[1]