main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/coin/conf"
  10. "go-common/app/service/main/coin/server/gorpc"
  11. grpc "go-common/app/service/main/coin/server/grpc"
  12. "go-common/app/service/main/coin/server/http"
  13. "go-common/app/service/main/coin/service"
  14. ecode "go-common/library/ecode/tip"
  15. "go-common/library/log"
  16. "go-common/library/net/trace"
  17. "go-common/library/queue/databus/report"
  18. )
  19. func main() {
  20. flag.Parse()
  21. if err := conf.Init(); err != nil {
  22. log.Error("conf.Init() error(%v)", err)
  23. panic(err)
  24. }
  25. log.Init(conf.Conf.Log)
  26. defer log.Close()
  27. trace.Init(conf.Conf.Tracer)
  28. defer trace.Close()
  29. ecode.Init(nil)
  30. log.Info("coin-service start")
  31. report.InitUser(conf.Conf.UserReport)
  32. // service init
  33. svr := service.New(conf.Conf)
  34. rpcSvr := rpc.New(conf.Conf, svr)
  35. grpcSvr := grpc.New(conf.Conf.GRPC, svr)
  36. http.Init(conf.Conf, svr)
  37. // init signal
  38. c := make(chan os.Signal, 1)
  39. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  40. for {
  41. s := <-c
  42. log.Info("coin-service get a signal %s", s.String())
  43. switch s {
  44. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  45. grpcSvr.Shutdown(context.TODO())
  46. rpcSvr.Close()
  47. svr.Close()
  48. time.Sleep(time.Second * 1)
  49. log.Info("coin-service exit")
  50. return
  51. case syscall.SIGHUP:
  52. // TODO reload
  53. default:
  54. return
  55. }
  56. }
  57. }