From 8b998ef67881e39045d9535ff8676ce65768761a Mon Sep 17 00:00:00 2001 From: Aleksandr Sokolov Date: Tue, 13 Aug 2024 20:28:02 +0300 Subject: [PATCH] Wait until systemd unmount completed && explicitly set stop timeout --- pkg/mounter/geesefs.go | 4 ++-- pkg/mounter/mounter.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/mounter/geesefs.go b/pkg/mounter/geesefs.go index 90c1139..04a467b 100644 --- a/pkg/mounter/geesefs.go +++ b/pkg/mounter/geesefs.go @@ -207,8 +207,8 @@ func (geesefs *geesefsMounter) Mount(target, volumeID string) error { } // force & lazy unmount to cleanup possibly dead mountpoints err = os.WriteFile( - unitPath+"/50-ExecStopPost.conf", - []byte("[Service]\nExecStopPost=/bin/umount -f -l "+target+"\n"), + unitPath+"/50-StopProps.conf", + []byte("[Service]\nExecStopPost=/bin/umount -f -l "+target+"\nTimeoutStopSec=20\n"), 0600, ) if err != nil { diff --git a/pkg/mounter/mounter.go b/pkg/mounter/mounter.go index 35ec801..d190f20 100644 --- a/pkg/mounter/mounter.go +++ b/pkg/mounter/mounter.go @@ -96,8 +96,20 @@ func SystemdUnmount(volumeID string) (bool, error) { if len(units) == 0 || units[0].ActiveState == "inactive" || units[0].ActiveState == "failed" { return true, nil } - _, err = conn.StopUnit(unitName, "replace", nil) - return true, err + + resCh := make(chan string) + defer close(resCh) + + _, err = conn.StopUnit(unitName, "replace", resCh) + if err != nil { + glog.Errorf("Failed to stop systemd unit (%s): %v", unitName, err) + return false, err + } + + res := <-resCh // wait until is stopped + glog.Infof("Systemd unit is stopped with result (%s): %s", unitName, res) + + return true, nil } func FuseUnmount(path string) error {