From c453acb6ccbbe7d565d33ef364f1301ffeb4fc11 Mon Sep 17 00:00:00 2001 From: Simone Mosciatti Date: Fri, 29 Jan 2021 13:44:33 +0100 Subject: [PATCH] catch also SIGTERM, from systemd --- main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 83783b0..9923bb6 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "os" "os/signal" "path/filepath" + "syscall" "google.golang.org/grpc" @@ -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") } @@ -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()) }