简体   繁体   English

DBus .service 文件丢失

[英]DBus .service file missing

I am building custom dbus service for my own demands and want it to start automatically when someone need it.我正在根据自己的需求构建自定义dbus服务,并希望它在有人需要时自动启动。 For that purpose I've created .service file like this为此,我创建了这样的.service文件

[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.我已将此文件放在名为 com.mycompany.servicename.service 的 /usr/share/dbus-1/services 文件夹中(我使用的是 Ubuntu 11.10) 可执行文件对每个人都有x权限。 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我得到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.在服务启动后立即注册路径为'/path/to/object' I just don't get why dbus can't find my .service file.我只是不明白为什么dbus找不到我的.service文件。 Maybe I am missing something?也许我错过了什么? Any ideas?有任何想法吗?

Edit I've managed to get D-BUS automatically start my script.编辑我设法让 D-BUS 自动启动我的脚本。 The section of .service file should be named [D-BUS Service] instead of [D-Bus service] .service文件的部分应该命名为[D-BUS Service]而不是[D-Bus service]

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 .XDG 基本目录规范中指定的目录之一中创建子目录dbus-1/services/ Usually, ~/.local/share/dbus-1/services/ works just fine.通常, ~/.local/share/dbus-1/services/工作得很好。 Enter the new subdirectory, create a file called com.mycompany.servicename.service and add the lines:进入新的子目录,创建一个名为com.mycompany.servicename.service的文件并添加以下行:

[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.请注意,d-BUS[D-BUS Service]需要资本化。

That's it!而已!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM