我创建了一个新的systemd服务,希望能够通过dbus调用来激活它。该服务仅执行一个shell脚本。

我在这里定义了服务:

/lib/systemd/system/testamundo.service


[Unit]
Description=Testamundo

[Service]
Type=dbus
BusName=org.freedesktop.testamundo
ExecStart=/home/test/systemd/testamundo.sh

我还在这里为它定义了D-Bus服务:
/usr/share/dbus-1/system-services

[D-BUS Service]
Name=org.freedesktop.testamundo
Exec=/usr/sbin/console-kit-daemon --no-daemon
User=root
SystemdService=testamundo.service

我正在尝试使用gdbus启动它,这是我正在尝试使用的命令:
sudo gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method org.freedesktop.systemd1.StartUnit "org.freedesktop.testamundo"

如果我像上面一样使用--system,该命令将返回Unknown Method错误,如果我使用--session,则该子进程将返回退出代码1。当我使用--session和--system查看journalctl时,可以看到该命令,但除此之外,没有其他信息。

感谢任何想法或建议,谢谢!

最佳答案

您的dbus命令正在使用不存在的接口(interface)。首先,它是org.freedesktop.systemd1.Manager.Start单位而不是org.freedesktop.systemd1.StartUnit。其次,org.freedesktop.systemd1.Manager.Start需要2个参数,服务名称和启动模式。引用:http://www.freedesktop.org/wiki/Software/systemd/dbus/

您已经定义了dbus服务,但是您通过直接要求systemd激活服务来绕过dbus。另一个要注意的是,dbus实际上是向systemd发送信号,而不是方法调用。

您已准备就绪,如果您仅对服务进行自省(introspection),则应将其激活。

sudo gdbus call --system --dest org.freedesktop.testamundo --object-path /org/freedesktop/testamundo --method org.freedesktop.DBus.Introspectable. Introspect

关于dbus - 使用gdbus启动systemd服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31415665/

10-10 12:36