main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "go-common/library/queue/databus/report"
  5. "os"
  6. "time"
  7. "go-common/app/admin/main/space/conf"
  8. "go-common/app/admin/main/space/http"
  9. "go-common/app/admin/main/space/service"
  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. http.Init(conf.Conf, s)
  31. report.InitManager(conf.Conf.ManagerReport)
  32. log.Info("space-admin start")
  33. ch := make(chan os.Signal, 1)
  34. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP)
  35. for {
  36. si := <-ch
  37. switch si {
  38. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  39. log.Info("get a signal %s, stop the space-admin process", si.String())
  40. time.Sleep(time.Second)
  41. return
  42. case syscall.SIGHUP:
  43. default:
  44. return
  45. }
  46. }
  47. }