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

AttributeError: 'SDInterface' object has no attribute 'GetProcesses' #27

Closed dabcoder closed 3 years ago

dabcoder commented 5 years ago
import pystemd
from pystemd.systemd1 import Unit

unit = Unit(b'ssh.service') . # tried with some other units too
unit.load()
unit.Service.GetProcesses()

I am getting:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SDInterface' object has no attribute 'GetProcesses'

Am I missing anything there?

aleivag commented 5 years ago

nope you are doing it right, here is my output

In [1]: c = pystemd.systemd1.Unit('crond.service', _autoload=True)

In [2]: c.Service.GetProcesses()
Out[2]: 
[(b'/system.slice/crond.service',
  26869,
  b'/usr/sbin/crond -n -m/usr/us/ops/scripts/mailops/cron_output_handler'),
 ...
...
 (b'/system.slice/crond.service', 1696433, b'/bin/sleep 282')]

Does GetProcesses exists in your version of systemd?, you can try to introspect the bus object (using busctl) to find if GetProcesses exists..

what version of systemd are you running?

dabcoder commented 5 years ago

what version of systemd are you running?

systemctl --version
systemd 237

busctl list doesn't give any indications with regards to GetProcesses. Is it due to a systemd version issue?

dabcoder commented 5 years ago

@aleivag I kept looking into this but given that GetProcesses does not exist in some less recent versions of systemd, would it make sense to add a quick comment in the README to clarify this point (I can issue a PR for that if so)? I also tried unsuccessfully to use busctl to gather more info, so if you have any more specific info to share on this topic, that'd be great (can also include that info in the README if it makes sense to add it).

Thanks!

kfix commented 5 years ago

GetProcesses was added in systemd/systemd@291d565a github says its in the v230 tag ...

kfix commented 5 years ago

oh it's "GetUnitProcesses"

kfix commented 3 years ago

looks like GetProcesses wasn't allowed until v238 by https://github.com/systemd/systemd/commit/a6011d1887f30867c8e8236605fdb2bbd2c386a5

dabcoder commented 3 years ago

Thanks for following up on that. I can issue a PR to add this as a comment in the README maybe.

davide125 commented 3 years ago

Closing as the PR was merged.