From bcb8029a80a579ec9b090fc8f5cb6584c7454d91 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 13 Feb 2024 01:16:53 +0300 Subject: [PATCH] Fix #92 - StopPost also does not work on old systemd versions, but /run/systemd/system/UNIT.d/ does! --- pkg/mounter/geesefs.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/mounter/geesefs.go b/pkg/mounter/geesefs.go index cd764e2..1b56325 100644 --- a/pkg/mounter/geesefs.go +++ b/pkg/mounter/geesefs.go @@ -155,11 +155,6 @@ func (geesefs *geesefsMounter) Mount(target, volumeID string) error { Value: dbus.MakeVariant("GeeseFS mount for Kubernetes volume "+volumeID), }, systemd.PropExecStart(args, false), - systemd.Property{ - Name: "ExecStopPost", - // force & lazy unmount to cleanup possibly dead mountpoints - Value: dbus.MakeVariant([]execCmd{ execCmd{ "/bin/umount", []string{ "/bin/umount", "-f", "-l", target }, false } }), - }, systemd.Property{ Name: "Environment", Value: dbus.MakeVariant([]string{ "AWS_ACCESS_KEY_ID="+geesefs.accessKeyID, "AWS_SECRET_ACCESS_KEY="+geesefs.secretAccessKey }), @@ -198,15 +193,17 @@ func (geesefs *geesefsMounter) Mount(target, volumeID string) error { conn.ResetFailedUnit(unitName) } } - _, err = conn.StartTransientUnit(unitName, "replace", newProps, nil) - if err != nil && strings.Index(err.Error(), "Cannot set property ExecStopPost") >= 0 { - // Maybe this is an old systemd where it's named StopPost - for i := range newProps { - if newProps[i].Name == "ExecStopPost" { - newProps[i].Name = "StopPost" - } + err = os.Mkdir("/run/systemd/system/" + unitName + ".d", 0755) + if err == nil { + // force & lazy unmount to cleanup possibly dead mountpoints + err = os.WriteFile( + "/run/systemd/system/" + unitName + ".d/50-ExecStopPost.conf", + []byte("[Service]\nExecStopPost=/bin/umount -f -l "+target+"\n"), + 0600, + ) + if err == nil { + _, err = conn.StartTransientUnit(unitName, "replace", newProps[0:len(newProps)-1], nil) } - _, err = conn.StartTransientUnit(unitName, "replace", newProps, nil) } if err != nil { return fmt.Errorf("Error starting systemd unit %s on host: %v", unitName, err)