main.go 1.2 KB

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