cmd: fix shutdown not being signaled properl
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
311ffa9f79
commit
05161db458
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
|
@ -17,6 +16,8 @@ import (
|
||||||
"goauthentik.io/internal/web"
|
"goauthentik.io/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var running = true
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
config.DefaultConfig()
|
config.DefaultConfig()
|
||||||
|
@ -44,31 +45,30 @@ func main() {
|
||||||
defer g.Kill()
|
defer g.Kill()
|
||||||
defer ws.Shutdown()
|
defer ws.Shutdown()
|
||||||
for {
|
for {
|
||||||
go attemptStartBackend(g, ex)
|
go attemptStartBackend(g)
|
||||||
ws.Start()
|
ws.Start()
|
||||||
// go attemptProxyStart(u, ex)
|
// go attemptProxyStart(u)
|
||||||
|
|
||||||
<-ex
|
<-ex
|
||||||
log.WithField("logger", "authentik").Debug("shutting down webserver")
|
running = false
|
||||||
|
log.WithField("logger", "authentik").Info("shutting down webserver")
|
||||||
go ws.Shutdown()
|
go ws.Shutdown()
|
||||||
log.WithField("logger", "authentik").Debug("killing gunicorn")
|
log.WithField("logger", "authentik").Info("killing gunicorn")
|
||||||
g.Kill()
|
g.Kill()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func attemptStartBackend(g *gounicorn.GoUnicorn, exitSignal chan os.Signal) error {
|
func attemptStartBackend(g *gounicorn.GoUnicorn) error {
|
||||||
for {
|
for {
|
||||||
err := g.Start()
|
err := g.Start()
|
||||||
select {
|
if !running {
|
||||||
case <-exitSignal:
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
|
||||||
log.WithField("logger", "authentik.g").WithError(err).Warning("gunicorn process died, restarting")
|
|
||||||
}
|
}
|
||||||
|
log.WithField("logger", "authentik.g").WithError(err).Warning("gunicorn process died, restarting")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func attemptProxyStart(u *url.URL, exitSignal chan os.Signal) error {
|
func attemptProxyStart(u *url.URL) error {
|
||||||
maxTries := 100
|
maxTries := 100
|
||||||
attempt := 0
|
attempt := 0
|
||||||
for {
|
for {
|
||||||
|
@ -93,12 +93,9 @@ func attemptProxyStart(u *url.URL, exitSignal chan os.Signal) error {
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
select {
|
if !running {
|
||||||
case <-exitSignal:
|
|
||||||
ac.Shutdown()
|
ac.Shutdown()
|
||||||
return nil
|
return nil
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (g *GoUnicorn) initCmd() {
|
||||||
|
|
||||||
func (g *GoUnicorn) Start() error {
|
func (g *GoUnicorn) Start() error {
|
||||||
if g.killed {
|
if g.killed {
|
||||||
g.log.Info("Not restarting gunicorn since we're killed")
|
g.log.Debug("Not restarting gunicorn since we're killed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if g.started {
|
if g.started {
|
||||||
|
|
Reference in New Issue