main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "time"
  6. "go-common/app/admin/main/tv/conf"
  7. "go-common/app/admin/main/tv/http"
  8. "go-common/app/admin/main/tv/service"
  9. ecode "go-common/library/ecode/tip"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. "go-common/library/os/signal"
  13. "go-common/library/syscall"
  14. )
  15. var (
  16. s *service.Service
  17. )
  18. func main() {
  19. flag.Parse()
  20. if err := conf.Init(); err != nil {
  21. log.Error("conf.Init() error(%v)", err)
  22. panic(err)
  23. }
  24. log.Init(conf.Conf.Log)
  25. defer log.Close()
  26. trace.Init(conf.Conf.Tracer)
  27. defer trace.Close()
  28. // service init
  29. s = service.New(conf.Conf)
  30. ecode.Init(conf.Conf.Ecode)
  31. http.Init(conf.Conf, s)
  32. log.Info("tv-admin start")
  33. signalHandler()
  34. }
  35. func signalHandler() {
  36. var (
  37. ch = make(chan os.Signal, 1)
  38. )
  39. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP)
  40. for {
  41. si := <-ch
  42. switch si {
  43. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  44. time.Sleep(time.Second * 2)
  45. log.Info("get a signal %s, stop the tv-admin process", si.String())
  46. s.Close()
  47. s.Wait()
  48. time.Sleep(time.Second)
  49. return
  50. case syscall.SIGHUP:
  51. default:
  52. return
  53. }
  54. }
  55. }