Make helmfile respect signals send by kill command (not only Ctrl+C in terminal) (#750)

Fixes #746 

Signed-off-by: Dmitry Chepurovskiy <me@dm3ch.net>
Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
Dmitry Chepurovskiy
2023-04-29 15:25:29 +09:00
committed by GitHub
co-authored by yxxhero
parent 3d0f0afe3a
commit aa5be82834
8 changed files with 64 additions and 18 deletions
+14 -8
View File
@@ -1,7 +1,6 @@
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
@@ -15,19 +14,25 @@ import (
func main() {
var sig os.Signal
sigs := make(chan os.Signal, 1)
errChan := make(chan error, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig = <-sigs
globalConfig := new(config.GlobalOptions)
rootCmd, err := cmd.NewRootCmd(globalConfig)
if err != nil {
errChan <- err
return
}
errChan <- rootCmd.Execute()
}()
globalConfig := new(config.GlobalOptions)
rootCmd, err := cmd.NewRootCmd(globalConfig)
errors.HandleExitCoder(err)
if err := rootCmd.Execute(); err != nil {
select {
case sig = <-sigs:
if sig != nil {
fmt.Fprintln(os.Stderr, err)
app.Cancel()
app.CleanWaitGroup.Wait()
// See http://tldp.org/LDP/abs/html/exitcodes.html
@@ -38,6 +43,7 @@ func main() {
os.Exit(143)
}
}
case err := <-errChan:
errors.HandleExitCoder(err)
}
}