Files
zurg/internal/mount/mount.go
2023-11-04 14:13:24 +01:00

39 lines
781 B
Go

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
}