internal: don't send kill signal to child as we mange it

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-07-17 17:02:24 +02:00
parent 7cbe33d65d
commit 311ffa9f79
2 changed files with 15 additions and 4 deletions

View File

@ -50,7 +50,7 @@ func main() {
<-ex <-ex
log.WithField("logger", "authentik").Debug("shutting down webserver") log.WithField("logger", "authentik").Debug("shutting down webserver")
ws.Shutdown() go ws.Shutdown()
log.WithField("logger", "authentik").Debug("killing gunicorn") log.WithField("logger", "authentik").Debug("killing gunicorn")
g.Kill() g.Kill()
} }

View File

@ -3,6 +3,7 @@ package gounicorn
import ( import (
"os" "os"
"os/exec" "os/exec"
"syscall"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"goauthentik.io/internal/config" "goauthentik.io/internal/config"
@ -12,6 +13,7 @@ type GoUnicorn struct {
log *log.Entry log *log.Entry
p *exec.Cmd p *exec.Cmd
started bool started bool
killed bool
} }
func NewGoUnicorn() *GoUnicorn { func NewGoUnicorn() *GoUnicorn {
@ -19,6 +21,7 @@ func NewGoUnicorn() *GoUnicorn {
g := &GoUnicorn{ g := &GoUnicorn{
log: logger, log: logger,
started: false, started: false,
killed: false,
} }
g.initCmd() g.initCmd()
return g return g
@ -33,14 +36,21 @@ func (g *GoUnicorn) initCmd() {
} }
g.log.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn") g.log.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn")
g.p = exec.Command(command, args...) g.p = exec.Command(command, args...)
g.p.Env = append(os.Environ(), g.p.Env = os.Environ()
"WORKERS=2", // 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.Stdout = os.Stdout
g.p.Stderr = os.Stderr g.p.Stderr = os.Stderr
} }
func (g *GoUnicorn) Start() error { func (g *GoUnicorn) Start() error {
if g.killed {
g.log.Info("Not restarting gunicorn since we're killed")
return nil
}
if g.started { if g.started {
g.initCmd() g.initCmd()
} }
@ -49,5 +59,6 @@ func (g *GoUnicorn) Start() error {
} }
func (g *GoUnicorn) Kill() error { func (g *GoUnicorn) Kill() error {
g.killed = true
return g.p.Process.Kill() return g.p.Process.Kill()
} }