main.go 1.0 KB

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