godbus / dbus

Native Go bindings for D-Bus
BSD 2-Clause "Simplified" License
976 stars 225 forks source link

help: Cannot set property ExecStopPost, or unknown property. #378

Closed jinjianming closed 2 weeks ago

jinjianming commented 8 months ago

The systemd service is an earlier version, and there was an error creating the systemd using dbus. ExecStopPost, or unknown property

systemctl --version
systemd 219
import (
    "fmt"
    systemd "github.com/coreos/go-systemd/v22/dbus"
    dbus "github.com/godbus/dbus/v5"
)
                 ...
    newProps := []systemd.Property{
                 ...
        systemd.PropExecStart(args, false),

        {
            Name: "ExecStopPost",
            // force & lazy unmount to cleanup possibly dead mountpoints
            Value: dbus.MakeVariant([]execCmd{execCmd{"/bin/umount", []string{"/bin/umount", "-f", "-l", "/xxx"}, false}}),
        },
                 ...
    }

    // The name of the transient service
    serviceName := "xxx.service"

    _, err = conn.StartTransientUnit(serviceName, "replace", newProps, nil)

I found the following error through dbus-monitor --system

method call time=1704875752.714736 sender=:1.0 -> destination=org.freedesktop.DBus serial=4741 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetConnectionUnixUser
   string ":1.202"
method return time=1704875752.714742 sender=org.freedesktop.DBus -> destination=:1.0 serial=122 reply_serial=4741
   uint32 0
error time=1704875752.715074 sender=:1.0 -> destination=:1.202 error_name=org.freedesktop.DBus.Error.PropertyReadOnly reply_serial=2
   string "Cannot set property ExecStopPost, or unknown property."
signal time=1704875752.715114 sender=:1.0 -> destination=(null destination) serial=4743 path=/org/freedesktop/systemd1; interface=org.freedesktop.systemd1.Manager; member=UnitNew
   string "my-transient-geesefs-mount.service"
jinjianming commented 8 months ago

I noticed that some materials seem to have this attribute renamed from StoppPost to ExecStoppPost in system v237, but I changed the code and the same issue with StoppPost. The only issue is that the attribute name was changed

guelfey commented 2 weeks ago

This is most likely not an issue with this library, but with the actual D-Bus interface of systemd you're trying to use. Please check the documentation for systemd or reach out to that project if you think its documentation is wrong.