From 7ab7b5df5ec90a637dba84b43faf93387d7d8674 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 28 Apr 2024 18:32:28 -0400 Subject: [PATCH] Fix signaler on Windows --- cmd/root.go | 25 ------------------------- cmd/signaller_nounix.go | 14 ++++++++++++++ cmd/signaller_unix.go | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 cmd/signaller_nounix.go create mode 100644 cmd/signaller_unix.go diff --git a/cmd/root.go b/cmd/root.go index 88ad695a3..01e926261 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -122,31 +122,6 @@ func startServer(ctx context.Context) func() error { } } -func startSignaler(ctx context.Context) func() error { - log.Info("Starting signaler") - scanner := GetScanner() - - return func() error { - var sigChan = make(chan os.Signal, 1) - signal.Notify(sigChan, syscall.SIGUSR1) - - for { - select { - case sig := <-sigChan: - log.Info("Received signal, triggering a new scan", "signal", sig) - start := time.Now() - err := scanner.RescanAll(ctx, false) - if err != nil { - log.Error("Error scanning", err) - } - log.Info("Triggered scan complete", "elapsed", time.Since(start).Round(100*time.Millisecond)) - case <-ctx.Done(): - return nil - } - } - } -} - func schedulePeriodicScan(ctx context.Context) func() error { return func() error { schedule := conf.Server.ScanSchedule diff --git a/cmd/signaller_nounix.go b/cmd/signaller_nounix.go new file mode 100644 index 000000000..602d65f83 --- /dev/null +++ b/cmd/signaller_nounix.go @@ -0,0 +1,14 @@ +//go:build windows || plan9 + +package cmd + +import ( + "context" +) + +// Windows and Plan9 don't support SIGUSR1, so we don't need to start a signaler +func startSignaler(ctx context.Context) func() error { + return func() error { + return nil + } +} diff --git a/cmd/signaller_unix.go b/cmd/signaller_unix.go new file mode 100644 index 000000000..b9163baba --- /dev/null +++ b/cmd/signaller_unix.go @@ -0,0 +1,40 @@ +//go:build !windows && !plan9 + +package cmd + +import ( + "context" + "os" + "os/signal" + "syscall" + "time" + + "github.com/navidrome/navidrome/log" +) + +const triggerScanSignal = syscall.SIGUSR1 + +func startSignaler(ctx context.Context) func() error { + log.Info(ctx, "Starting signaler") + scanner := GetScanner() + + return func() error { + var sigChan = make(chan os.Signal, 1) + signal.Notify(sigChan, triggerScanSignal) + + for { + select { + case sig := <-sigChan: + log.Info(ctx, "Received signal, triggering a new scan", "signal", sig) + start := time.Now() + err := scanner.RescanAll(ctx, false) + if err != nil { + log.Error(ctx, "Error scanning", err) + } + log.Info(ctx, "Triggered scan complete", "elapsed", time.Since(start).Round(100*time.Millisecond)) + case <-ctx.Done(): + return nil + } + } + } +}