Commit 80c1171c authored by Vitaliy Filippov's avatar Vitaliy Filippov
Browse files

Improve error handling, do not remove CollectMode (fix #101)

parent 11d8b4bf
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -193,18 +193,21 @@ func (geesefs *geesefsMounter) Mount(target, volumeID string) error {
			conn.ResetFailedUnit(unitName)
		}
	}
	err = os.MkdirAll("/run/systemd/system/" + unitName + ".d", 0755)
	if err == nil {
	unitPath := "/run/systemd/system/" + unitName + ".d"
	err = os.MkdirAll(unitPath, 0755)
	if err != nil {
		return fmt.Errorf("Error creating directory %s: %v", unitPath, err)
	}
	// force & lazy unmount to cleanup possibly dead mountpoints
	err = os.WriteFile(
			"/run/systemd/system/" + unitName + ".d/50-ExecStopPost.conf",
		unitPath+"/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)
		}
	if err != nil {
		return fmt.Errorf("Error writing %v/50-ExecStopPost.conf: %v", unitPath, err)
	}
	_, err = conn.StartTransientUnit(unitName, "replace", newProps, nil)
	if err != nil {
		return fmt.Errorf("Error starting systemd unit %s on host: %v", unitName, err)
	}