-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: handle signals properly #1129
Conversation
cmd/bank-vaults/main.go
Outdated
@@ -99,6 +101,16 @@ var rootCmd = &cobra.Command{ | |||
// Execute adds all child commands to the root command sets flags appropriately. | |||
// This is called by main.main(). It only needs to happen once to the rootCmd. | |||
func execute() { | |||
// Handle signals to prevent bad exit codes on `docker stop`. | |||
// TODO: robably a more sophisticated exit procedure should be implemented in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: robably a more sophisticated exit procedure should be implemented in the future. | |
// TODO: probably a more sophisticated exit procedure should be implemented in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's not a bad idea. :D
cmd/bank-vaults/main.go
Outdated
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGABRT) | ||
go func() { | ||
for range sigs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for for
. <-sigs
should work.
Signed-off-by: Nandor Kracser <bonifaido@gmail.com>
Signed-off-by: Nandor Kracser <bonifaido@gmail.com>
Signed-off-by: Nandor Kracser bonifaido@gmail.com
What's in this PR?
Handling signals, and do a 0 status code exit.
Why?
If signals are not captured the CLI exits with status code 2.
Additional context
Checklist