main.go 1018 B

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