main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/tv/internal/conf"
  10. "go-common/app/service/main/tv/internal/server/grpc"
  11. "go-common/app/service/main/tv/internal/server/http"
  12. "go-common/app/service/main/tv/internal/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("tv-service start")
  24. trace.Init(conf.Conf.Tracer)
  25. defer trace.Close()
  26. svc := service.New(conf.Conf)
  27. grpcServ := grpc.New(conf.Conf.GRPC, svc)
  28. http.Init(conf.Conf, svc)
  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. svc.Close()
  37. grpcServ.Shutdown(context.Background())
  38. log.Info("tv-service exit")
  39. time.Sleep(time.Second)
  40. return
  41. case syscall.SIGHUP:
  42. default:
  43. return
  44. }
  45. }
  46. }