Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to ListUnits of systemd user units via DBus? #43

Open
dckc opened this issue Oct 1, 2018 · 0 comments
Open

how to ListUnits of systemd user units via DBus? #43

dckc opened this issue Oct 1, 2018 · 0 comments

Comments

@dckc
Copy link
Owner

dckc commented Oct 1, 2018

I'm trying to use systemd to manage a node.js service (finquick @@IOU link), and
I'd like something on my taskbar to tell me whether it's running. But I can't
figure out how to get the ListUnits dbus method to work on the SessionBus.

Works as expected:

$ dbus-send --system --print-reply --reply-timeout=2000 --type=method_call   --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.ListUnits
...
         object path "/org/freedesktop/systemd1/unit/devfsd_2eservice"
         uint32 0
         string ""
         object path "/"
      }
   ]

fails:

connolly@jambox:~$ dbus-send --print-reply --reply-timeout=2000 --type=method_call   --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.ListUnits
Error org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1

I started out using python Popen and systemctl --user status --all --output=json but --output=json doesn't apply to status of units; only to journal entries. In a Jun 2015 discussion, the systemd folks endorse DBus for this sort of thing.

https://zignar.net/2014/09/08/getting-started-with-dbus-python-systemd/ works just fine, but only for the SystemBus. When I try the SessionBus, I lose:

python my_services_applet.py
Traceback (most recent call last):
  File "my_services_applet.py", line 123, in <module>
    _test1()
  File "my_services_applet.py", line 55, in _test1
    manager = systemd_manager(SessionBus())
  File "my_services_applet.py", line 42, in systemd_manager
    '/org/freedesktop/systemd1')
  File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 241, in get_object
    follow_name_owner_changes=follow_name_owner_changes)
...
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1

systemd/systemd#5247 close, but arch (and Fedora?). I'm using Ubuntu.

@dckc dckc changed the title how to ListUnits of UserSession? how to ListUnits of systemd user units via DBus? Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant