internal: fix gunicorn not being restarted correctly
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
be9ca48de0
commit
7cbe33d65d
|
@ -9,32 +9,42 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type GoUnicorn struct {
|
type GoUnicorn struct {
|
||||||
log *log.Entry
|
log *log.Entry
|
||||||
p *exec.Cmd
|
p *exec.Cmd
|
||||||
|
started bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGoUnicorn() *GoUnicorn {
|
func NewGoUnicorn() *GoUnicorn {
|
||||||
logger := log.WithField("logger", "authentik.g.unicorn")
|
logger := log.WithField("logger", "authentik.g.unicorn")
|
||||||
|
g := &GoUnicorn{
|
||||||
|
log: logger,
|
||||||
|
started: false,
|
||||||
|
}
|
||||||
|
g.initCmd()
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GoUnicorn) initCmd() {
|
||||||
command := "gunicorn"
|
command := "gunicorn"
|
||||||
args := []string{"-c", "./lifecycle/gunicorn.conf.py", "authentik.root.asgi:application"}
|
args := []string{"-c", "./lifecycle/gunicorn.conf.py", "authentik.root.asgi:application"}
|
||||||
if config.G.Debug {
|
if config.G.Debug {
|
||||||
command = "python"
|
command = "python"
|
||||||
args = []string{"manage.py", "runserver", "localhost:8000"}
|
args = []string{"manage.py", "runserver", "localhost:8000"}
|
||||||
}
|
}
|
||||||
logger.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn")
|
g.log.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn")
|
||||||
p := exec.Command(command, args...)
|
g.p = exec.Command(command, args...)
|
||||||
p.Env = append(os.Environ(),
|
g.p.Env = append(os.Environ(),
|
||||||
"WORKERS=2",
|
"WORKERS=2",
|
||||||
)
|
)
|
||||||
p.Stdout = os.Stdout
|
g.p.Stdout = os.Stdout
|
||||||
p.Stderr = os.Stderr
|
g.p.Stderr = os.Stderr
|
||||||
return &GoUnicorn{
|
|
||||||
log: logger,
|
|
||||||
p: p,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GoUnicorn) Start() error {
|
func (g *GoUnicorn) Start() error {
|
||||||
|
if g.started {
|
||||||
|
g.initCmd()
|
||||||
|
}
|
||||||
|
g.started = true
|
||||||
return g.p.Run()
|
return g.p.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue