internal: start embedded outpost directly after backend is healthy instead of waiting
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3b47cb64da
commit
6deddd038f
|
@ -68,6 +68,7 @@ outposts:
|
||||||
|
|
||||||
cookie_domain: null
|
cookie_domain: null
|
||||||
disable_update_check: false
|
disable_update_check: false
|
||||||
|
disable_startup_analytics: false
|
||||||
avatars: env://AUTHENTIK_AUTHENTIK__AVATARS?gravatar
|
avatars: env://AUTHENTIK_AUTHENTIK__AVATARS?gravatar
|
||||||
geoip: "./GeoLite2-City.mmdb"
|
geoip: "./GeoLite2-City.mmdb"
|
||||||
|
|
||||||
|
|
|
@ -437,19 +437,20 @@ if _ERROR_REPORTING:
|
||||||
"Error reporting is enabled",
|
"Error reporting is enabled",
|
||||||
env=CONFIG.y("error_reporting.environment", "customer"),
|
env=CONFIG.y("error_reporting.environment", "customer"),
|
||||||
)
|
)
|
||||||
get_http_session().post(
|
if not CONFIG.y_bool("disable_startup_analytics", False):
|
||||||
"https://goauthentik.io/api/event",
|
get_http_session().post(
|
||||||
json={
|
"https://goauthentik.io/api/event",
|
||||||
"domain": "authentik",
|
json={
|
||||||
"name": "pageview",
|
"domain": "authentik",
|
||||||
"url": f"http://localhost/{env}",
|
"name": "pageview",
|
||||||
"referrer": f"{__version__} ({build_hash})",
|
"url": f"http://localhost/{env}",
|
||||||
},
|
"referrer": f"{__version__} ({build_hash})",
|
||||||
headers={
|
},
|
||||||
"User-Agent": sha512(SECRET_KEY.encode("ascii")).hexdigest()[:16],
|
headers={
|
||||||
"Content-Type": "text/plain",
|
"User-Agent": sha512(SECRET_KEY.encode("ascii")).hexdigest()[:16],
|
||||||
},
|
"Content-Type": "text/plain",
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||||
|
|
|
@ -56,15 +56,17 @@ func main() {
|
||||||
|
|
||||||
g := gounicorn.NewGoUnicorn()
|
g := gounicorn.NewGoUnicorn()
|
||||||
ws := web.NewWebServer(g)
|
ws := web.NewWebServer(g)
|
||||||
|
g.HealthyCallback = func() {
|
||||||
|
if !config.G.Web.DisableEmbeddedOutpost {
|
||||||
|
go attemptProxyStart(ws, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
defer g.Kill()
|
defer g.Kill()
|
||||||
defer ws.Shutdown()
|
defer ws.Shutdown()
|
||||||
go web.RunMetricsServer()
|
go web.RunMetricsServer()
|
||||||
for {
|
for {
|
||||||
go attemptStartBackend(g)
|
go attemptStartBackend(g)
|
||||||
ws.Start()
|
ws.Start()
|
||||||
if !config.G.Web.DisableEmbeddedOutpost {
|
|
||||||
go attemptProxyStart(ws, u)
|
|
||||||
}
|
|
||||||
|
|
||||||
<-ex
|
<-ex
|
||||||
running = false
|
running = false
|
||||||
|
@ -88,8 +90,6 @@ func attemptStartBackend(g *gounicorn.GoUnicorn) {
|
||||||
func attemptProxyStart(ws *web.WebServer, u *url.URL) {
|
func attemptProxyStart(ws *web.WebServer, u *url.URL) {
|
||||||
maxTries := 100
|
maxTries := 100
|
||||||
attempt := 0
|
attempt := 0
|
||||||
// Sleep to wait for the app server to start
|
|
||||||
time.Sleep(30 * time.Second)
|
|
||||||
for {
|
for {
|
||||||
log.WithField("logger", "authentik").Debug("attempting to init outpost")
|
log.WithField("logger", "authentik").Debug("attempting to init outpost")
|
||||||
ac := ak.NewAPIController(*u, config.G.SecretKey)
|
ac := ak.NewAPIController(*u, config.G.SecretKey)
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type GoUnicorn struct {
|
type GoUnicorn struct {
|
||||||
|
HealthyCallback func()
|
||||||
|
|
||||||
log *log.Entry
|
log *log.Entry
|
||||||
p *exec.Cmd
|
p *exec.Cmd
|
||||||
started bool
|
started bool
|
||||||
|
@ -21,10 +23,11 @@ type GoUnicorn struct {
|
||||||
func NewGoUnicorn() *GoUnicorn {
|
func NewGoUnicorn() *GoUnicorn {
|
||||||
logger := log.WithField("logger", "authentik.router.unicorn")
|
logger := log.WithField("logger", "authentik.router.unicorn")
|
||||||
g := &GoUnicorn{
|
g := &GoUnicorn{
|
||||||
log: logger,
|
log: logger,
|
||||||
started: false,
|
started: false,
|
||||||
killed: false,
|
killed: false,
|
||||||
alive: false,
|
alive: false,
|
||||||
|
HealthyCallback: func() {},
|
||||||
}
|
}
|
||||||
g.initCmd()
|
g.initCmd()
|
||||||
return g
|
return g
|
||||||
|
@ -76,6 +79,7 @@ func (g *GoUnicorn) healthcheck() {
|
||||||
for range time.Tick(time.Second) {
|
for range time.Tick(time.Second) {
|
||||||
if check() {
|
if check() {
|
||||||
g.log.Info("backend is alive, backing off with healthchecks")
|
g.log.Info("backend is alive, backing off with healthchecks")
|
||||||
|
g.HealthyCallback()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
g.log.Debug("backend not alive yet")
|
g.log.Debug("backend not alive yet")
|
||||||
|
|
Reference in New Issue