From 311ffa9f79a3c1119149a7478d3ce04b376f78c7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Jul 2021 17:02:24 +0200 Subject: [PATCH] internal: don't send kill signal to child as we mange it Signed-off-by: Jens Langhammer --- cmd/server/main.go | 2 +- internal/gounicorn/gounicorn.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 0119a5fe3..e7db0fb2c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -50,7 +50,7 @@ func main() { <-ex log.WithField("logger", "authentik").Debug("shutting down webserver") - ws.Shutdown() + go ws.Shutdown() log.WithField("logger", "authentik").Debug("killing gunicorn") g.Kill() } diff --git a/internal/gounicorn/gounicorn.go b/internal/gounicorn/gounicorn.go index 958fcbb86..c08071253 100644 --- a/internal/gounicorn/gounicorn.go +++ b/internal/gounicorn/gounicorn.go @@ -3,6 +3,7 @@ package gounicorn import ( "os" "os/exec" + "syscall" log "github.com/sirupsen/logrus" "goauthentik.io/internal/config" @@ -12,6 +13,7 @@ type GoUnicorn struct { log *log.Entry p *exec.Cmd started bool + killed bool } func NewGoUnicorn() *GoUnicorn { @@ -19,6 +21,7 @@ func NewGoUnicorn() *GoUnicorn { g := &GoUnicorn{ log: logger, started: false, + killed: false, } g.initCmd() return g @@ -33,14 +36,21 @@ func (g *GoUnicorn) initCmd() { } g.log.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn") g.p = exec.Command(command, args...) - g.p.Env = append(os.Environ(), - "WORKERS=2", - ) + g.p.Env = os.Environ() + // Don't pass ctrl-c to child + // since we handle it ourselves + g.p.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + } g.p.Stdout = os.Stdout g.p.Stderr = os.Stderr } func (g *GoUnicorn) Start() error { + if g.killed { + g.log.Info("Not restarting gunicorn since we're killed") + return nil + } if g.started { g.initCmd() } @@ -49,5 +59,6 @@ func (g *GoUnicorn) Start() error { } func (g *GoUnicorn) Kill() error { + g.killed = true return g.p.Process.Kill() }