From fb65690abd5c190dce30d3cfe0d079b27040a309 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 8 May 2023 10:09:33 -0400 Subject: [PATCH] fix: add shutdown signal and flag for renterd --- main.go | 10 ++++++++-- renterd/main.go | 24 +++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 0d86380..e9c045e 100644 --- a/main.go +++ b/main.go @@ -90,10 +90,16 @@ func main() { app.Get("/swagger/{any:path}", swaggerUI) // Start the Iris app and listen for incoming requests on port 80 - log.Fatal(app.Listen(":8080", func(app *iris.Application) { + err := app.Listen(":8080", func(app *iris.Application) { routes := app.GetRoutes() for _, route := range routes { log.Println(route) } - })) + }) + + if err != nil { + log.Fatal(err) + } + + renterd.ShutdownComplete() } diff --git a/renterd/main.go b/renterd/main.go index 64fe2e3..108eb26 100644 --- a/renterd/main.go +++ b/renterd/main.go @@ -46,11 +46,13 @@ var ( builddate = "?" // fetched once, then cached - apiPassword *string - apiAddr *string - seed *types.PrivateKey - ready = make(chan bool) - readyFired = false + apiPassword *string + apiAddr *string + seed *types.PrivateKey + ready = make(chan bool) + readyFired = false + shutdown = make(chan bool) + shutdownFired = false ) func check(context string, err error) { @@ -367,6 +369,8 @@ func Main() { log.Fatalf("Shutdown function %v failed: %v", i+1, err) } } + + shutdown <- true } func GetApiAddr() string { @@ -382,3 +386,13 @@ func Ready() bool { return true } + +func ShutdownComplete() bool { + if shutdownFired { + return true + } + + shutdownFired = <-shutdown + + return true +}