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)
// 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()
}

View File

@ -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
}