From 5355160850acf66290fdfdc7ef3c28802b364aa2 Mon Sep 17 00:00:00 2001 From: Nancy Hong Date: Fri, 26 Jul 2024 16:26:46 -0700 Subject: [PATCH] feat: support for exit zero sigterm --- cmd/errors.go | 5 +++++ cmd/root.go | 8 +++++++- internal/proxy/proxy.go | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/errors.go b/cmd/errors.go index 8739eb53..489a92b6 100644 --- a/cmd/errors.go +++ b/cmd/errors.go @@ -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. diff --git a/cmd/root.go b/cmd/root.go index e8de80a8..b252dd6c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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", @@ -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 + } } }() diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 81c4f82f..c1e3f56f 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -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