main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/aegis/conf"
  9. "go-common/app/admin/main/aegis/server/http"
  10. "go-common/app/admin/main/aegis/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. panic(err)
  20. }
  21. log.Init(conf.Conf.Log)
  22. defer log.Close()
  23. log.Info("aegis-admin start")
  24. if conf.Conf.Debug != "local" {
  25. trace.Init(nil)
  26. defer trace.Close()
  27. ecode.Init(nil)
  28. }
  29. // report init
  30. report.InitManager(nil)
  31. svc := service.New(conf.Conf)
  32. http.Init(conf.Conf, svc)
  33. c := make(chan os.Signal, 1)
  34. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  35. for {
  36. s := <-c
  37. log.Info("get a signal %s", s.String())
  38. switch s {
  39. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  40. svc.Close()
  41. log.Info("aegis-admin exit")
  42. time.Sleep(time.Second)
  43. return
  44. case syscall.SIGHUP:
  45. default:
  46. return
  47. }
  48. }
  49. }