Skip to content

Managing a "user unit file" via dbus, how?  #436

Open
@shadyabhi

Description

I'm puzzled on how to manage a "user service" via this package. Help is greatly appreciated.

func TestGithubIssue(t *testing.T) {
	ctx := context.Background()
	dbusConn, err := dbus.NewUserConnectionContext(ctx)
	require.NoError(t, err, "creating new dbus connection")
	defer dbusConn.Close()

	spew.Dump(dbusConn.GetUnitPropertiesContext(ctx, "longrunning.service"))
}

Outputs:-

=== RUN   TestGithubIssue
(map[string]interface {}) <nil>
(dbus.Error) Process org.freedesktop.systemd1 exited with status 1

However, from CLI, I'm able to get the status of service.

➤ systemctl --user status longrunning.service
○ longrunning.service - longrunning
     Loaded: loaded (/home/arastogi/.config/systemd/user/longrunning.service; static)
     Active: inactive (dead)

I was able to find this previous Github issue, but it didn't really have an answer. #424 (comment)

I tried sending dbus messages directly, I get the same error.

➤ eval `dbus-launch --auto-syntax`

>>>  0s elapsed...
➜ $?=0 @arastogi-ld1 bincontrol/systemd (master↑1|✚3…) [5:53:26]
➤ dbus-send --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.StartUnit string:'[email protected]' string:'replace'
Error org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1

My research so far below:-

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions