Use routine.Manager in router

This commit is contained in:
Sasha Koshka 2023-05-26 13:07:05 -04:00
parent 23f7497622
commit 3c7b964cfe

View File

@ -23,7 +23,7 @@ const banner = "\n" +
" '/" " '/"
func main () { func main () {
// setup logging // set up logging
logDir := os.Getenv("HNAKRA_LOG_DIR") logDir := os.Getenv("HNAKRA_LOG_DIR")
if logDir != "" { if logDir != "" {
logger, err := rotate.New(logDir) logger, err := rotate.New(logDir)
@ -33,7 +33,6 @@ func main () {
rcon := rcon.New("/debug/rcon") rcon := rcon.New("/debug/rcon")
originalWriter := log.Writer() originalWriter := log.Writer()
log.SetOutput(io.MultiWriter(originalWriter, rcon)) log.SetOutput(io.MultiWriter(originalWriter, rcon))
log.Println(banner) log.Println(banner)
// load config // load config
@ -55,10 +54,18 @@ func main () {
}) })
rcon.SetConfig(conf) rcon.SetConfig(conf)
// start servers // set up servers
log.Println("... starting up") log.Println("... starting up")
manager := routines.Manager { RestartDeadline: time.Second * 8 }
rout := router.New(conf) rout := router.New(conf)
srvhnakra := &srvhnakra.Server { Config: conf, Router: rout } 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) rcon.SetRouter(rout)
if conf.RconEnable() { if conf.RconEnable() {
err = rout.HTTPMux().Handle("@/debug/rcon/", rcon) err = rout.HTTPMux().Handle("@/debug/rcon/", rcon)
@ -66,12 +73,9 @@ func main () {
} else { } else {
log.SetOutput(originalWriter) log.SetOutput(originalWriter)
} }
if conf.HTTPSEnable() {
srvhttps := &srvhttps.Server { Config: conf, Handler: rout } // run servers
go httpsRoutine(srvhttps) err = manager.Run()
}
err = srvhnakra.ListenAndServe()
if err != nil { log.Println("XXX", err) } if err != nil { log.Println("XXX", err) }
} }