From 3c7b964cfe1cd78022badcb3dc22834d0023fded Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 26 May 2023 13:07:05 -0400 Subject: [PATCH] Use routine.Manager in router --- cmd/router/main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/router/main.go b/cmd/router/main.go index 8e515e0..5138a52 100644 --- a/cmd/router/main.go +++ b/cmd/router/main.go @@ -23,7 +23,7 @@ const banner = "\n" + " '/" func main () { - // setup logging + // set up logging logDir := os.Getenv("HNAKRA_LOG_DIR") if logDir != "" { logger, err := rotate.New(logDir) @@ -33,7 +33,6 @@ func main () { rcon := rcon.New("/debug/rcon") originalWriter := log.Writer() log.SetOutput(io.MultiWriter(originalWriter, rcon)) - log.Println(banner) // load config @@ -55,10 +54,18 @@ func main () { }) rcon.SetConfig(conf) - // start servers + // set up servers log.Println("... starting up") + manager := routines.Manager { RestartDeadline: time.Second * 8 } rout := router.New(conf) srvhnakra := &srvhnakra.Server { Config: conf, Router: rout } + manager.Append(srvhnakra.ListenAndServe) + if conf.HTTPSEnable() { + srvhttps := &srvhttps.Server { Config: conf, Handler: rout } + manager.Append(srvhttps.ListenAndServe) + } + + // set up rcon rcon.SetRouter(rout) if conf.RconEnable() { err = rout.HTTPMux().Handle("@/debug/rcon/", rcon) @@ -66,12 +73,9 @@ func main () { } else { log.SetOutput(originalWriter) } - if conf.HTTPSEnable() { - srvhttps := &srvhttps.Server { Config: conf, Handler: rout } - go httpsRoutine(srvhttps) - } - - err = srvhnakra.ListenAndServe() + + // run servers + err = manager.Run() if err != nil { log.Println("XXX", err) } }