main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/live/zeus/internal/conf"
  10. "go-common/app/service/live/zeus/internal/server/grpc"
  11. "go-common/app/service/live/zeus/internal/server/http"
  12. "go-common/app/service/live/zeus/internal/service"
  13. ecode "go-common/library/ecode/tip"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. v1srv "go-common/app/service/live/zeus/internal/service/v1"
  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("zeus-service start")
  26. trace.Init(conf.Conf.Tracer)
  27. defer trace.Close()
  28. ecode.Init(conf.Conf.Ecode)
  29. svc := service.New(conf.Conf)
  30. zeus := v1srv.NewZeusService(conf.Conf)
  31. grpcServer := grpc.New(conf.Conf, zeus)
  32. defer grpcServer.Shutdown(context.Background())
  33. http.Init(conf.Conf, svc, zeus)
  34. c := make(chan os.Signal, 1)
  35. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. s := <-c
  38. log.Info("get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. svc.Close()
  42. log.Info("zeus-service exit")
  43. time.Sleep(time.Second)
  44. return
  45. case syscall.SIGHUP:
  46. default:
  47. return
  48. }
  49. }
  50. }