现在,我正在使用D-Bus API为golang启动一个systemd服务(我的服务只是调用一个shell脚本)。
我在/usr/share/dbus-1/system-services/org.freedesktop.hello.service上做了一个D总线服务。
[D-BUS Service]
Name=org.freedesktop.hello
Exec=/bin/false
User=root
SystemdService=hello.service和/lib/ systemd /system/hello.service中的systemd服务。
[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不管我在戈朗的错误是什么,
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)
}关于这件事我没有太多的信息,所以我想得到一些帮助。谢谢!
发布于 2017-11-16 07:18:25
sudo gdbus call --system ...在公共汽车上。
...
conn, error1 := dbus.SessionBus()
...这是在会话总线上。
尝试使用类似于dbus.SystemBus()的东西。
https://stackoverflow.com/questions/47320709
复制相似问题