【问题标题】:.Service File D-Bus.Service 文件 D-Bus
【发布时间】:2011-12-08 13:20:15
【问题描述】:

我正在尝试在我的客户端程序启动时自动启动 DBus 服务。我已经设置了一个 .service 文件,但它不起作用。

我的服务名称是

org.fandingo.PMP

我用

向 python 服务器注册名称
 name = dbus.service.BusName('org.fandingo.PMP', session_bus)
 object = PMPService(session_bus, '/PMPService', PMPProxy())

如果我从客户端手动运行服务器代码,我可以连接到这个很好

remote = bus.get_object('org.fandingo.PMP', '/PMPService')

因此,如果手动调用,服务器和客户端都可以工作。如果我只是尝试客户端,我会得到以下 Python 异常

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.fandingo.PMP was not provided by any .service files

这是我的 .service 文件

-rw-r--r--. root root unconfined_u:object_r:usr_t:s0   /usr/share/dbus-1/services/org.fandingo.PMP.service

这些权限和 SELinux 标签与其他 .service 文件相同。

.service 文件内容

[D-Bus Service]
Name=org.fandingo.PMP
Exec=/home/fandingo/code/python/pmp/src/pmpserver.py
User=fandingo

pmpserver.py 是可执行的并且具有正确的 shebang。

有人发现我的配置有什么问题吗?

谢谢,

【问题讨论】:

    标签: dbus


    【解决方案1】:

    终于想通了。

    我不确定 .service 文件是如何执行的,但它们没有正确设置 /bin/env。

    我的 shebang 工作不正常:

    #!/usr/bin/env python
    

    我将服务文件更改为

    [D-Bus Service]
    Name=org.fandingo.PMP
    Exec=python /home/fandingo/code/python/pmp/src/pmpserver.py
    

    现在一切都很好。

    【讨论】:

    • env 更常见的位置是 /usr/bin。至少在 Linux 上它是存在的。
    猜你喜欢
    • 2011-10-29
    • 2015-08-17
    • 2010-12-01
    • 2019-06-01
    • 2011-02-07
    • 1970-01-01
    • 2019-04-26
    • 2012-09-04
    • 2010-12-31
    相关资源
    最近更新 更多