mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 08:32:48 +02:00
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:
co-authored by
yxxhero
parent
3d0f0afe3a
commit
aa5be82834
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user