main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/videoup/conf"
  9. "go-common/app/admin/main/videoup/http"
  10. "go-common/app/admin/main/videoup/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  14. "go-common/library/queue/databus/report"
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(); err != nil {
  19. log.Error("conf.Init() error(%v)", err)
  20. panic(err)
  21. }
  22. // init log
  23. log.Init(conf.Conf.Xlog)
  24. trace.Init(conf.Conf.Tracer)
  25. defer trace.Close()
  26. defer log.Close()
  27. log.Info("videoup-admin start")
  28. report.InitManager(conf.Conf.ManagerReport)
  29. ecode.Init(conf.Conf.Ecode)
  30. // service init
  31. svr := service.New(conf.Conf)
  32. http.Init(conf.Conf, svr)
  33. // init signal
  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("videoup-admin get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  41. svr.Close()
  42. log.Info("videoup-admin exit")
  43. time.Sleep(1 * time.Second)
  44. return
  45. case syscall.SIGHUP:
  46. // TODO reload
  47. default:
  48. return
  49. }
  50. }
  51. }