diff --git a/cmd/server/server.go b/cmd/server/server.go index ba0cdb54fc..85556ed304 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "net/url" - "syscall" "time" "github.com/getsentry/sentry-go" @@ -20,7 +19,6 @@ import ( sentryutils "goauthentik.io/internal/utils/sentry" webutils "goauthentik.io/internal/utils/web" "goauthentik.io/internal/web" - "goauthentik.io/internal/worker" ) var rootCmd = &cobra.Command{ @@ -58,14 +56,6 @@ var rootCmd = &cobra.Command{ panic(err) } - worker := worker.New() - if config.Get().Worker.Embedded { - err = worker.Start() - if err != nil { - panic(err) - } - } - ws := web.NewWebServer() ws.Core().AddHealthyCallback(func() { if config.Get().Outposts.DisableEmbeddedOutpost { @@ -77,7 +67,6 @@ var rootCmd = &cobra.Command{ <-ex l.Info("shutting down webserver") go ws.Shutdown() - go worker.Kill(syscall.SIGTERM) }, } diff --git a/internal/config/struct.go b/internal/config/struct.go index 8eff328de3..4bd4cd97c3 100644 --- a/internal/config/struct.go +++ b/internal/config/struct.go @@ -7,7 +7,6 @@ type Config struct { ErrorReporting ErrorReportingConfig `yaml:"error_reporting" env:", prefix=AUTHENTIK_ERROR_REPORTING__"` Redis RedisConfig `yaml:"redis" env:", prefix=AUTHENTIK_REDIS__"` Outposts OutpostConfig `yaml:"outposts" env:", prefix=AUTHENTIK_OUTPOSTS__"` - Worker WorkerConfig `yaml:"worker" env:", prefix=AUTHENTIK_WORKER__"` // Config for core and embedded outpost SecretKey string `yaml:"secret_key" env:"AUTHENTIK_SECRET_KEY, overwrite"` @@ -78,7 +77,3 @@ type OutpostConfig struct { type WebConfig struct { Path string `yaml:"path" env:"PATH, overwrite"` } - -type WorkerConfig struct { - Embedded bool `yaml:"embedded" env:"EMBEDDED, overwrite"` -} diff --git a/internal/worker/worker.go b/internal/worker/worker.go deleted file mode 100644 index b1ff348614..0000000000 --- a/internal/worker/worker.go +++ /dev/null @@ -1,115 +0,0 @@ -package worker - -import ( - "fmt" - "os" - "os/exec" - "os/signal" - "runtime" - "syscall" - - log "github.com/sirupsen/logrus" - - "goauthentik.io/internal/config" -) - -type Worker struct { - Healthcheck func() bool - HealthyCallback func() - - log *log.Entry - p *exec.Cmd - pidFile string - started bool - killed bool -} - -func New() *Worker { - logger := log.WithField("logger", "authentik.router.worker") - w := &Worker{ - log: logger, - started: false, - killed: false, - } - w.initCmd() - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM) - go func() { - for sig := range c { - switch sig { - case syscall.SIGHUP: - w.log.Info("SIGHUP received, forwarding to dramatiq") - w.Reload() - case syscall.SIGINT: - w.log.Info("SIGINT received, stopping dramatiq") - w.Kill(syscall.SIGINT) - case syscall.SIGTERM: - w.log.Info("SIGTERM received, stopping dramatiq") - w.Kill(syscall.SIGTERM) - } - } - }() - return w -} - -func (w *Worker) initCmd() { - command := "./manage.py" - args := []string{"worker"} - if config.Get().Debug { - args = append(args, "--reload") - } - - pidFile, err := os.CreateTemp("", "authentik-dramatiq.pid") - if err != nil { - panic(fmt.Errorf("failed to create temporary pid file: %v", err)) - } - w.pidFile = pidFile.Name() - args = append(args, "--pid-file", w.pidFile) - - w.log.WithField("args", args).WithField("cmd", command).Debug("Starting dramatiq") - w.p = exec.Command(command, args...) - w.p.Env = os.Environ() - w.p.Stdout = os.Stdout - w.p.Stderr = os.Stderr -} - -func (w *Worker) Start() error { - if !w.started { - w.initCmd() - } - w.killed = false - w.started = true - return w.p.Run() -} - -func (w *Worker) Reload() { - w.log.WithField("method", "reload").Info("reloading dramatiq") - err := w.p.Process.Signal(syscall.SIGHUP) - if err != nil { - w.log.WithError(err).Warning("failed to reload dramatiq") - } -} - -func (w *Worker) Kill(sig syscall.Signal) { - if !w.started { - return - } - var err error - if runtime.GOOS == "darwin" { - w.log.WithField("method", "processKill").Warning("stopping dramatiq") - err = w.p.Process.Kill() - } else { - w.log.WithField("method", "syscallKill").Warning("stopping dramatiq") - err = syscall.Kill(w.p.Process.Pid, sig) - } - if err != nil { - w.log.WithError(err).Warning("failed to stop dramatiq") - } - if w.pidFile != "" { - err := os.Remove(w.pidFile) - if err != nil { - w.log.WithError(err).Warning("failed to remove pidfile") - } - } - w.killed = true -}