diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 567137fd5..ae16c3184 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -29,7 +29,7 @@ var AppVersion, GitCommit string func acceptSignals(migrationContext *base.MigrationContext) { c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP) + signal.Notify(c, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT) go func() { for sig := range c { switch sig { @@ -40,6 +40,14 @@ func acceptSignals(migrationContext *base.MigrationContext) { } else { migrationContext.MarkPointOfInterest() } + case syscall.SIGTERM, syscall.SIGINT: + migrationContext.Log.Infof("Received %s. Initiating graceful shutdown", sig) + select { + case migrationContext.PanicAbort <- fmt.Errorf("received signal: %s", sig): + default: + migrationContext.Log.Errorf("failed to send abort signal, forcing exit") + os.Exit(1) + } } } }()