Skip to content

Commit

Permalink
feat: support for exit zero sigterm (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
nancynh authored Jul 29, 2024
1 parent 9973141 commit 790b935
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 790b935

Please sign in to comment.