2021-05-02 22:49:16 +00:00
|
|
|
package gounicorn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"goauthentik.io/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GoUnicorn struct {
|
|
|
|
log *log.Entry
|
2021-06-23 18:40:51 +00:00
|
|
|
p *exec.Cmd
|
2021-05-02 22:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGoUnicorn() *GoUnicorn {
|
2021-06-23 18:40:51 +00:00
|
|
|
logger := log.WithField("logger", "authentik.g.unicorn")
|
2021-05-02 22:49:16 +00:00
|
|
|
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"}
|
|
|
|
}
|
2021-06-23 18:40:51 +00:00
|
|
|
logger.WithField("args", args).WithField("cmd", command).Debug("Starting gunicorn")
|
2021-05-02 22:49:16 +00:00
|
|
|
p := exec.Command(command, args...)
|
|
|
|
p.Env = append(os.Environ(),
|
|
|
|
"WORKERS=2",
|
|
|
|
)
|
|
|
|
p.Stdout = os.Stdout
|
|
|
|
p.Stderr = os.Stderr
|
2021-06-23 18:40:51 +00:00
|
|
|
return &GoUnicorn{
|
|
|
|
log: logger,
|
|
|
|
p: p,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GoUnicorn) Start() error {
|
|
|
|
return g.p.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GoUnicorn) Kill() error {
|
|
|
|
return g.p.Process.Kill()
|
2021-05-02 22:49:16 +00:00
|
|
|
}
|