fix: add shutdown signal and flag for renterd

This commit is contained in:
Derrick Hammer 2023-05-08 10:09:33 -04:00
parent 4e6c29f1fd
commit fb65690abd
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 27 additions and 7 deletions

10
main.go
View File

@ -90,10 +90,16 @@ func main() {
app.Get("/swagger/{any:path}", swaggerUI) app.Get("/swagger/{any:path}", swaggerUI)
// Start the Iris app and listen for incoming requests on port 80 // 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() routes := app.GetRoutes()
for _, route := range routes { for _, route := range routes {
log.Println(route) log.Println(route)
} }
})) })
if err != nil {
log.Fatal(err)
}
renterd.ShutdownComplete()
} }

View File

@ -51,6 +51,8 @@ var (
seed *types.PrivateKey seed *types.PrivateKey
ready = make(chan bool) ready = make(chan bool)
readyFired = false readyFired = false
shutdown = make(chan bool)
shutdownFired = false
) )
func check(context string, err error) { func check(context string, err error) {
@ -367,6 +369,8 @@ func Main() {
log.Fatalf("Shutdown function %v failed: %v", i+1, err) log.Fatalf("Shutdown function %v failed: %v", i+1, err)
} }
} }
shutdown <- true
} }
func GetApiAddr() string { func GetApiAddr() string {
@ -382,3 +386,13 @@ func Ready() bool {
return true return true
} }
func ShutdownComplete() bool {
if shutdownFired {
return true
}
shutdownFired = <-shutdown
return true
}