Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from cvmfs/unmountall_when_exiting
Browse files Browse the repository at this point in the history
catch also SIGTERM, from systemd
  • Loading branch information
siscia authored Jan 29, 2021
2 parents 04bb5fd + c453acb commit c9e6d8a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/signal"
"path/filepath"
"syscall"

"google.golang.org/grpc"

Expand Down Expand Up @@ -72,7 +73,6 @@ func main() {

// Configure filesystem and snapshotter
fs, err := cvmfs.NewFilesystem(ctx, filepath.Join(*rootDir, "cvmfs"), config)
defer fs.(*cvmfs.Filesystem).UnmountAll(ctx)
if err != nil {
log.G(ctx).WithError(err).Fatalf("failed to configure filesystem")
}
Expand Down Expand Up @@ -121,12 +121,13 @@ func main() {
log.G(ctx).WithError(err).Fatalf("error on serving via socket %q", *address)
}
}()
waitForSIGINT()
waitForSignal(fs.(*cvmfs.Filesystem))
log.G(ctx).Info("Got SIGINT")
}

func waitForSIGINT() {
func waitForSignal(fs *cvmfs.Filesystem) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
fs.UnmountAll(context.TODO())
}

0 comments on commit c9e6d8a

Please sign in to comment.