Resolve race condition issues
This commit is contained in:
38
internal/mount/mount.go
Normal file
38
internal/mount/mount.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package mount
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"github.com/mdlayher/sdnotify"
|
||||
)
|
||||
|
||||
func Mount(mountpoint string) error {
|
||||
n, err := sdnotify.New()
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
log.Fatalf("failed to open systemd notifier: %v", err)
|
||||
}
|
||||
err = n.Notify(
|
||||
sdnotify.Statusf("service started successfully"),
|
||||
sdnotify.Ready,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to send ready notification: %v", err)
|
||||
}
|
||||
return Unmount(mountpoint, n)
|
||||
}
|
||||
|
||||
func Unmount(mountpoint string, n *sdnotify.Notifier) error {
|
||||
log.Println("Unmounting...")
|
||||
err := n.Notify(
|
||||
sdnotify.Statusf("service stopped successfully"),
|
||||
sdnotify.Ready,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to send stop notification: %v", err)
|
||||
}
|
||||
fuse.Unmount(mountpoint)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user