8

I am building custom dbus service for my own demands and want it to start automatically when someone need it. For that purpose I've created .service file like this

[D-Bus Service]
Name=com.mycompany.servicename
Exec=/home/myuser/Workspace/service-start
User=myuser

Here I just changed the actual name of service and executable but this is not the point. I've double checked real names - it matches exactly. I've placed this file under name com.mycompany.servicename.service to /usr/share/dbus-1/services folder (I am using Ubuntu 11.10) Executable file has x permissions for everyone. And here is the problem - when I am trying to start client that performs

bus = dbus.SessionBus()
bus.get_object('com.mycompany.servicename','/path/to/object')

I get dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name com.mycompany.servicename was not provided by any .service files

Object with path '/path/to/object' is registered right after service start. I just don't get why dbus can't find my .service file. Maybe I am missing something? Any ideas?

Edit I've managed to get D-BUS automatically start my script. The section of .service file should be named [D-BUS Service] instead of [D-Bus service]

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
pss
  • 736
  • 3
  • 7
  • 14
  • Where are you putting your .service file? The man page for dbus-daemon refers to the XDG Base Dir Spec, and that intern seems to suggest you should put it in ~/.local/share (see http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html) – Lawrence D'Oliveiro Feb 09 '12 at 06:22
  • Unfortunately there is no evidence of other `.service` files that provide `session buses` but at the same time there are a lot of them in the folder I mentioned earlier (/usr/share/dbus-1/services). The name of the folder I got [here](http://techbase.kde.org/Development/Tutorials/D-Bus/Autostart_Services) – pss Feb 16 '12 at 18:02
  • @pss, you should create a answer and accept it by yourself! – Yasushi Shoji Aug 18 '12 at 07:02

1 Answers1

4

Here's a short summary of the comments...

Create the subdirectory dbus-1/services/ in one of the directories named in the XDG Base Directory Specification. Usually, ~/.local/share/dbus-1/services/ works just fine. Enter the new subdirectory, create a file called com.mycompany.servicename.service and add the lines:

[D-BUS Service]
Name=com.mycompany.servicename
Exec=/home/myuser/Workspace/service-start
User=myuser

Please note that D-BUS in [D-BUS Service] needs to be capitalized.

That's it!

mzuther
  • 1,158
  • 1
  • 13
  • 24
  • 3
    does this mean that the dbus-daemon would want to manage my service? (I expect myself to start my application *manually* that would register itself on dbus for a particular message interface and object path via dbus-python. But I get the `ServiceUnknown` exception.) – n611x007 Nov 15 '13 at 19:26