 5e72ec9c0c
			
		
	
	5e72ec9c0c
	
	
	
		
			
			* initial subpath support Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make outpost compatible Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix static files somewhat Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix web interface Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix most static stuff Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix most web links Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix websocket Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix URL for static files Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format web Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add root redirect for subpath Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * set cookie path Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Update internal/config/struct.go Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens L. <jens@beryju.org> * fix sfe Signed-off-by: Jens Langhammer <jens@goauthentik.io> * bump required version Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix flow background Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint and some more links Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix impersonate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Signed-off-by: Jens L. <jens@goauthentik.io> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
		
			
				
	
	
		
			77 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"net/http"
 | |
| 	"os"
 | |
| 	"path"
 | |
| 	"strings"
 | |
| 	"time"
 | |
| 
 | |
| 	log "github.com/sirupsen/logrus"
 | |
| 	"github.com/spf13/cobra"
 | |
| 	"goauthentik.io/internal/config"
 | |
| 	"goauthentik.io/internal/utils/web"
 | |
| )
 | |
| 
 | |
| var workerHeartbeat = path.Join(os.TempDir(), "authentik-worker")
 | |
| 
 | |
| const workerThreshold = 30
 | |
| 
 | |
| var healthcheckCmd = &cobra.Command{
 | |
| 	Use: "healthcheck",
 | |
| 	Run: func(cmd *cobra.Command, args []string) {
 | |
| 		if len(args) < 1 {
 | |
| 			os.Exit(1)
 | |
| 		}
 | |
| 		mode := args[0]
 | |
| 		exitCode := 1
 | |
| 		log.WithField("mode", mode).Debug("checking health")
 | |
| 		switch strings.ToLower(mode) {
 | |
| 		case "server":
 | |
| 			exitCode = checkServer()
 | |
| 		case "worker":
 | |
| 			exitCode = checkWorker()
 | |
| 		default:
 | |
| 			log.Warn("Invalid mode")
 | |
| 		}
 | |
| 		os.Exit(exitCode)
 | |
| 	},
 | |
| }
 | |
| 
 | |
| func init() {
 | |
| 	rootCmd.AddCommand(healthcheckCmd)
 | |
| }
 | |
| 
 | |
| func checkServer() int {
 | |
| 	h := &http.Client{
 | |
| 		Transport: web.NewUserAgentTransport("goauthentik.io/healthcheck", http.DefaultTransport),
 | |
| 	}
 | |
| 	url := fmt.Sprintf("http://%s%s-/health/live/", config.Get().Listen.HTTP, config.Get().Web.Path)
 | |
| 	res, err := h.Head(url)
 | |
| 	if err != nil {
 | |
| 		log.WithError(err).Warning("failed to send healthcheck request")
 | |
| 		return 1
 | |
| 	}
 | |
| 	if res.StatusCode >= 400 {
 | |
| 		log.WithField("status", res.StatusCode).Warning("unhealthy status code")
 | |
| 		return 1
 | |
| 	}
 | |
| 	log.Debug("successfully checked health")
 | |
| 	return 0
 | |
| }
 | |
| 
 | |
| func checkWorker() int {
 | |
| 	stat, err := os.Stat(workerHeartbeat)
 | |
| 	if err != nil {
 | |
| 		log.WithError(err).Warning("failed to check worker heartbeat file")
 | |
| 		return 1
 | |
| 	}
 | |
| 	delta := time.Since(stat.ModTime()).Seconds()
 | |
| 	if delta > workerThreshold {
 | |
| 		log.WithField("threshold", workerThreshold).WithField("delta", delta).Warning("Worker hasn't updated heartbeat in threshold")
 | |
| 		return 1
 | |
| 	}
 | |
| 	return 0
 | |
| }
 |