main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/dm/conf"
  9. "go-common/app/admin/main/dm/http"
  10. "go-common/app/admin/main/dm/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  14. manager "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 func() {
  27. log.Close()
  28. // wait for a while to guarantee that all log messages are written
  29. time.Sleep(10 * time.Millisecond)
  30. }()
  31. // ecode init
  32. ecode.Init(conf.Conf.Ecode)
  33. // manager log init
  34. manager.InitManager(conf.Conf.ManagerLog)
  35. // service init
  36. svc := service.New(conf.Conf)
  37. http.Init(conf.Conf, svc)
  38. log.Info("dm-admin start")
  39. // init signal
  40. c := make(chan os.Signal, 1)
  41. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  42. for {
  43. s := <-c
  44. log.Info("dm-admin get a signal %s", s.String())
  45. switch s {
  46. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  47. log.Info("dm-admin exit")
  48. return
  49. case syscall.SIGHUP:
  50. // TODO reload
  51. default:
  52. return
  53. }
  54. }
  55. }