Zug*_*dud 7 dbus systemd gdbus
我创建了一个新的 systemd 服务,我希望能够通过 dbus 调用激活它。该服务只是执行一个 shell 脚本。
我在这里定义了服务:
/lib/systemd/system/testamundo.service
[Unit]
Description=Testamundo
[Service]
Type=dbus
BusName=org.freedesktop.testamundo
ExecStart=/home/test/systemd/testamundo.sh
Run Code Online (Sandbox Code Playgroud)
我还在这里为它定义了一个 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
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 gdbus 启动它,这是我尝试使用的命令:
sudo gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method org.freedesktop.systemd1.StartUnit "org.freedesktop.testamundo"
Run Code Online (Sandbox Code Playgroud)
如果我像上面那样使用 --system 命令返回一个未知方法错误,如果我使用 --session 它从子进程返回退出代码 1。当我使用 --session 和 --system 查看 journalctl 时,我可以看到命令,但除此之外没有其他信息。
感谢您的任何想法或建议,谢谢!
您的 dbus 命令正在使用不存在的接口。首先它是org.freedesktop.systemd1.Manager.Startunit not org.freedesktop.systemd1.StartUnit。其次,org.freedesktop.systemd1.Manager.Start需要2个参数,服务名和启动方式。参考:http : //www.freedesktop.org/wiki/Software/systemd/dbus/
您已经定义了一个 dbus 服务,但是您通过直接要求 systemd 激活该服务来绕过 dbus。其他注意事项是,dbus 实际上向 systemd 发送信号而不是方法调用。
你已经准备好了一切,如果你只是对你的服务进行内省,它应该被激活。
sudo gdbus call --system --dest org.freedesktop.testamundo --object-path /org/freedesktop/testamundo --method org.freedesktop.DBus.Introspectable. Introspect
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5843 次 |
| 最近记录: |