main.go 1.3 KB

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