mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
pwreset: Stop daemon on restart, dont fail if json is malformed
daemon now stops on the RESTART signal, and when it fails to read JSON, it no longer stops the whole daemon.
This commit is contained in:
parent
d688dd02c8
commit
f88f71d933
3
main.go
3
main.go
@ -586,11 +586,13 @@ func start(asDaemon, firstCall bool) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
for range RESTART {
|
for range RESTART {
|
||||||
|
println("got it too!")
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := SRV.Shutdown(ctx); err != nil {
|
if err := SRV.Shutdown(ctx); err != nil {
|
||||||
app.err.Fatalf("Server shutdown error: %s", err)
|
app.err.Fatalf("Server shutdown error: %s", err)
|
||||||
}
|
}
|
||||||
|
app.info.Println("Server shut down.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,6 +610,7 @@ func (app *appContext) shutdown() {
|
|||||||
if err := SRV.Shutdown(cntx); err != nil {
|
if err := SRV.Shutdown(cntx); err != nil {
|
||||||
app.err.Fatalf("Server shutdown error: %s", err)
|
app.err.Fatalf("Server shutdown error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,13 @@ func (app *appContext) StartPWR() {
|
|||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
|
||||||
done := make(chan bool)
|
|
||||||
go pwrMonitor(app, watcher)
|
go pwrMonitor(app, watcher)
|
||||||
err = watcher.Add(path)
|
err = watcher.Add(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf("Failed to start password reset daemon: %s", err)
|
app.err.Printf("Failed to start password reset daemon: %s", err)
|
||||||
}
|
}
|
||||||
<-done
|
|
||||||
|
<-RESTART
|
||||||
}
|
}
|
||||||
|
|
||||||
// PasswordReset represents a passwordreset-xyz.json file generated by Jellyfin.
|
// PasswordReset represents a passwordreset-xyz.json file generated by Jellyfin.
|
||||||
@ -77,7 +77,7 @@ func pwrMonitor(app *appContext, watcher *fsnotify.Watcher) {
|
|||||||
err = json.Unmarshal(data, &pwr)
|
err = json.Unmarshal(data, &pwr)
|
||||||
if len(pwr.Pin) == 0 || err != nil {
|
if len(pwr.Pin) == 0 || err != nil {
|
||||||
app.debug.Printf("PWR: Failed to read PIN: %v", err)
|
app.debug.Printf("PWR: Failed to read PIN: %v", err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
app.info.Printf("New password reset for user \"%s\"", pwr.Username)
|
app.info.Printf("New password reset for user \"%s\"", pwr.Username)
|
||||||
if currentTime := time.Now(); pwr.Expiry.After(currentTime) {
|
if currentTime := time.Now(); pwr.Expiry.After(currentTime) {
|
||||||
|
Loading…
Reference in New Issue
Block a user