2

I'd like to start a python script that uses pydbus to listen for incoming commands via D-Bus on boot, and it needs root permissions. It would be nice if it can be stopped and restarted via systemctl, so I don't want to put it into /etc/rc.local.

The script is based on this example.

I can run the script just fine in a terminal, both in an X11 session and in tty, and send commands to my dbus server. But when starting it via a systemd .service file it complains about gi.repository.GLib.Error: g-io-error-quark: Cannot autolaunch D-Bus without X11 $DISPLAY (0), because I have been using SessionBus. So I went to using SystemBus instead and now get permission errors: Connection ":1.474" is not allowed to own the service which is probably associated with the conf in /etc/dbus-1/system.d/.

So I looked at some other service to see how they work:

  • /usr/share/dbus-1/system-services/org.manjaro.pamac.daemon.service
  • /etc/dbus-1/system.d/org.manjaro.pamac.daemon.conf
  • /usr/lib/systemd/system/pamac-daemon.service

Is this all the stuff that I need to use? It's just so incredibly troublesome, and everything I try results in new errors.

Are there any good resources on how to do this?

How would one start the linked example above on boot using a systemd .service file?

5
  • 1
    Can you be more specific on "...it complains about some X11 $DISPLAY stuff." ? Dec 21, 2020 at 2:38
  • did. I think I'm getting close, I might just answer my own question at some point today
    – sezanzeb
    Dec 21, 2020 at 10:48
  • I'm still getting a The name was not provided by any .service files error
    – sezanzeb
    Dec 21, 2020 at 11:34
  • it was because my pydbus client also needs to use SystemBus to connect. Now it's GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Rejected send message
    – sezanzeb
    Dec 21, 2020 at 11:53
  • It works now, I'm going to make an example setup on github on post it as answer here in the evening
    – sezanzeb
    Dec 21, 2020 at 12:10

1 Answer 1

0

I made a working example:

https://github.com/sezanzeb/systemd-pydbus-example

I didn't need the /usr/share/dbus-1/system-services/org.manjaro.pamac.daemon.service file in the end.

2
  • IMO the answer is too short when github code is too complex to me to quickly see how you solved the issues in the question.Could you please add details here? Feb 20, 2022 at 8:59
  • I'm afraid there is no short answer to this, the example on github is already as short as it gets. About the specific problems in the question, I don't remember them anymore so I can't give more details about them, sorry
    – sezanzeb
    Feb 21, 2022 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .