Skip to content

Add signal exit-code option #131

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ramonberrutti
Copy link

@ramonberrutti ramonberrutti commented May 28, 2025

The change maintains backwards compatibility since the default value is still 1.

Fix #130

New Feature: Configurable Exit Code

  • Global variable added: Introduced globalExitCode as an integer to store the configurable exit code. (main.go, main.goR86)
  • CLI flag added: Added a new --exit-code flag to allow users to specify the exit code when the program terminates. The default value is set to 1. (main.go, main.goR1386-R1390)
  • Signal handling updated: Modified the signal handling logic to use globalExitCode for program termination instead of a hardcoded value. (main.go, main.goL1245-R1247)
  • Flag initialization: Set globalExitCode to the value provided by the --exit-code flag during program initialization. (main.go, main.goR1079)

The change maintains backwards compatibility since the default value is still 1.
Fix minio#130
@jonashartwig
Copy link

jonashartwig commented Jun 10, 2025

This does the trick and will solve our use case as well. Thanks

An enhancement could be to configure the exit code not globally but based on received signal.
e.g. --exitCodeOnSignal 15:0 that on a signal 15 it will exit with 0, any other signal exits on 1. the exitCodeOnSignal should be a multiflag or a list if possible :)

@@ -1242,7 +1244,7 @@ func sidekickMain(ctx *cli.Context) {
})
default:
console.Infof("caught signal '%s'\n", signal)
os.Exit(1)
os.Exit(globalExitCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not so keen to add new flags. I think all what you need to do is to run os.Exit(143) when we receive syscall.SIGTERM. Kubernetes will understand that and will not flag an error for the container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle term signal gracefully
3 participants