Skip to content

Commit

Permalink
Fix #92 - StopPost also does not work on old systemd versions, but /r…
Browse files Browse the repository at this point in the history
…un/systemd/system/UNIT.d/ does!
  • Loading branch information
vitalif committed Feb 12, 2024
1 parent 700508e commit bcb8029
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions pkg/mounter/geesefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bcb8029

Please sign in to comment.