main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/bbq/sys-msg/internal/conf"
  10. "go-common/app/service/bbq/sys-msg/internal/server/grpc"
  11. "go-common/app/service/bbq/sys-msg/internal/server/http"
  12. "go-common/app/service/bbq/sys-msg/internal/service"
  13. ecode "go-common/library/ecode/tip"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. )
  17. func main() {
  18. flag.Parse()
  19. if err := conf.Init(); err != nil {
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. log.Info("sys-msg-service start")
  25. trace.Init(conf.Conf.Tracer)
  26. defer trace.Close()
  27. ecode.Init(conf.Conf.Ecode)
  28. svc := service.New(conf.Conf)
  29. grpcServ := grpc.New(conf.Conf.GRPC, svc)
  30. http.Init(conf.Conf, svc)
  31. c := make(chan os.Signal, 1)
  32. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  33. for {
  34. s := <-c
  35. log.Info("get a signal %s", s.String())
  36. switch s {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  38. svc.Close()
  39. grpcServ.Shutdown(context.Background())
  40. log.Info("sys-msg-service exit")
  41. time.Sleep(time.Second)
  42. return
  43. case syscall.SIGHUP:
  44. default:
  45. return
  46. }
  47. }
  48. }