From 7cbe33d65dae3da7a5034878b71ca1e6eea678df Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Jul 2021 16:59:31 +0200 Subject: [PATCH] internal: fix gunicorn not being restarted correctly Signed-off-by: Jens Langhammer --- internal/gounicorn/gounicorn.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/gounicorn/gounicorn.go b/internal/gounicorn/gounicorn.go index cdbc907c8..958fcbb86 100644 --- a/internal/gounicorn/gounicorn.go +++ b/internal/gounicorn/gounicorn.go @@ -9,32 +9,42 @@ import ( ) type GoUnicorn struct { - log *log.Entry - p *exec.Cmd + log *log.Entry + p *exec.Cmd + started bool } func NewGoUnicorn() *GoUnicorn { logger := log.WithField("logger", "authentik.g.unicorn") + g := &GoUnicorn{ + log: logger, + started: false, + } + g.initCmd() + return g +} + +func (g *GoUnicorn) initCmd() { command := "gunicorn" args := []string{"-c", "./lifecycle/gunicorn.conf.py", "authentik.root.asgi:application"} if config.G.Debug { command = "python" args = []string{"manage.py", "runserver", "localhost:8000"} } - logger.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn") - p := exec.Command(command, args...) - p.Env = append(os.Environ(), + 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", ) - p.Stdout = os.Stdout - p.Stderr = os.Stderr - return &GoUnicorn{ - log: logger, - p: p, - } + g.p.Stdout = os.Stdout + g.p.Stderr = os.Stderr } func (g *GoUnicorn) Start() error { + if g.started { + g.initCmd() + } + g.started = true return g.p.Run() }