Skip to content
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

feat: support for exit zero sigterm #684

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var (
Code: 143,
}

errSigTermZero = &exitError{
Err: errors.New("SIGTERM signal received"),
Code: 0,
}

errQuitQuitQuit = &exitError{
Err: errors.New("/quitquitquit received request"),
Code: 0, // This error guarantees a clean exit.
Expand Down
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ CPU may be throttled and a background refresh cannot run reliably
)
localFlags.StringVar(&c.conf.StaticConnectionInfo, "static-connection-info",
"", "JSON file with static connection info. See --help for format.")
localFlags.BoolVar(&c.conf.ExitZeroOnSigterm, "exit-zero-sigterm", false,
"Exit with 0 exit code when Sigterm received (default is 143)")

// Global and per instance flags
localFlags.StringVarP(&c.conf.Addr, "address", "a", "127.0.0.1",
Expand Down Expand Up @@ -1049,7 +1051,11 @@ func runSignalWrapper(cmd *Command) (err error) {
case syscall.SIGINT:
shutdownCh <- errSigInt
case syscall.SIGTERM:
shutdownCh <- errSigTerm
if cmd.conf.ExitZeroOnSigterm {
shutdownCh <- errSigTermZero
} else {
shutdownCh <- errSigTerm
}
}
}()

Expand Down
3 changes: 3 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ type Config struct {
// StaticConnectionInfo is the file path for a static connection info JSON
// file. See the proxy help message for details on its format.
StaticConnectionInfo string

// ExitZeroOnSigterm exits with 0 exit code when Sigterm received
ExitZeroOnSigterm bool
}

// dialOptions interprets appropriate dial options for a particular instance
Expand Down
Loading