main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/interface/live/push-live/conf"
  8. "go-common/app/interface/live/push-live/http"
  9. "go-common/app/interface/live/push-live/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. "time"
  13. )
  14. func main() {
  15. flag.Parse()
  16. if err := conf.Init(); err != nil {
  17. log.Error("conf.Init() error(%v)", err)
  18. panic(err)
  19. }
  20. // init log
  21. log.Init(conf.Conf.Log)
  22. // init trace
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. defer log.Close()
  26. log.Info("push-live start")
  27. // service init
  28. srv := service.New(conf.Conf)
  29. http.Init(conf.Conf, srv)
  30. // init pprof conf.Conf.Perf
  31. // init signal
  32. c := make(chan os.Signal, 1)
  33. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  34. for {
  35. s := <-c
  36. log.Info("push-live get a signal %s", s.String())
  37. switch s {
  38. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  39. srv.Close()
  40. log.Info("push-live exit")
  41. time.Sleep(time.Second)
  42. return
  43. case syscall.SIGHUP:
  44. default:
  45. return
  46. }
  47. }
  48. }