add hooks for service

This commit is contained in:
ginuerzh
2022-11-03 21:32:12 +08:00
parent b86d7ee06d
commit 09c12b013c
4 changed files with 46 additions and 47 deletions

View File

@ -6,13 +6,16 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/go-gost/core/logger"
"github.com/go-gost/x/config"
"github.com/go-gost/x/config/parsing"
xlogger "github.com/go-gost/x/logger"
xmetrics "github.com/go-gost/x/metrics"
"github.com/go-gost/x/registry"
)
var (
@ -142,11 +145,25 @@ func main() {
svc := svc
go func() {
svc.Serve()
svc.Close()
// svc.Close()
}()
}
config.SetGlobal(cfg)
select {}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
for sig := range sigs {
switch sig {
case syscall.SIGHUP:
return
default:
for name, srv := range registry.ServiceRegistry().GetAll() {
srv.Close()
log.Debugf("service %s shutdown", name)
}
return
}
}
}

View File

@ -1,5 +1,5 @@
package main
const (
version = "3.0.0-beta.6"
version = "3.0.0-beta.7"
)