main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/admin/main/manager/conf"
  10. "go-common/app/admin/main/manager/server/grpc"
  11. "go-common/app/admin/main/manager/server/http"
  12. "go-common/app/admin/main/manager/service"
  13. "go-common/library/log"
  14. "go-common/library/net/trace"
  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.Log)
  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. // service init
  32. svc := service.New(conf.Conf)
  33. grpcSvc := grpc.New(conf.Conf.WardenServer, svc)
  34. http.Init(conf.Conf, svc)
  35. log.Info("manager-admin start")
  36. // init signal
  37. c := make(chan os.Signal, 1)
  38. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  39. for {
  40. s := <-c
  41. log.Info("manager-admin get a signal %s", s.String())
  42. switch s {
  43. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  44. grpcSvc.Shutdown(context.Background())
  45. svc.Close()
  46. log.Info("manager-admin exit")
  47. return
  48. case syscall.SIGHUP:
  49. // TODO reload
  50. default:
  51. return
  52. }
  53. }
  54. }