使用Golang启动D-Bus服务
我现在正在处理调用并启动一个systemd服务,我只是使用golang的D-BusAPI调用一个shell脚本 我在/usr/share/dbus-1/system services/org.freedesktop.hello.service中创建了一个D-Bus服务使用Golang启动D-Bus服务,go,dbus,Go,Dbus,我现在正在处理调用并启动一个systemd服务,我只是使用golang的D-BusAPI调用一个shell脚本 我在/usr/share/dbus-1/system services/org.freedesktop.hello.service中创建了一个D-Bus服务 [D-BUS Service] Name=org.freedesktop.hello Exec=/bin/false User=root SystemdService=hello.service [Unit] Descripti
[D-BUS Service]
Name=org.freedesktop.hello
Exec=/bin/false
User=root
SystemdService=hello.service
[Unit]
Description=Hello
[Service]
Type=dbus
BusName=org.freedesktop.hello
ExecStart=/opt/hello.sh
和/lib/systemd/system/hello.service中的systemd服务
[D-BUS Service]
Name=org.freedesktop.hello
Exec=/bin/false
User=root
SystemdService=hello.service
[Unit]
Description=Hello
[Service]
Type=dbus
BusName=org.freedesktop.hello
ExecStart=/opt/hello.sh
我正在尝试实现下面代码的相同结果,这是有效的
sudo gdbus call --system --dest org.freedesktop.hello --object-path /org/freedesktop/hello --method org.freedesktop.DBus.Introspectable.Introspect
但是我一直在Golang发现错误
The name org.freedesktop.hello was not provided by any .service files
我现在的代码是
package main
import (
"encoding/json"
"github.com/godbus/dbus"
"os"
"github.com/godbus/dbus/introspect"
)
func main() {
conn, error1 := dbus.SessionBus()
if error1 != nil {
panic(error1)
}
node, err2 := introspect.Call(conn.Object("org.freedesktop.hello", "/org/freedesktop/hello"))
if err2 != nil {
panic(err2)
}
data, _ := json.MarshalIndent(node, "", " ")
os.Stdout.Write(data)
}
关于这个东西的信息不多,所以我想得到一些帮助。谢谢
sudo gdbus call --system ...
在系统总线上
...
conn, error1 := dbus.SessionBus()
...
这是在会话总线上
尝试使用dbus.SystemBus之类的工具。错误消息似乎来自systemd。添加.service文件后是否运行了systemctl daemon reload?是的,我确实重新加载了daemon,但仍然收到相同的错误。您救了我的命!谢谢!希望这能帮助其他面临类似问题的人。