main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/open/conf"
  9. "go-common/app/admin/main/open/http"
  10. "go-common/app/admin/main/open/service"
  11. "go-common/library/log"
  12. "go-common/library/net/trace"
  13. )
  14. func main() {
  15. flag.Parse()
  16. if err := conf.Init(); err != nil {
  17. log.Error("conf.Init() error(%v)", err)
  18. panic(err)
  19. }
  20. // init log
  21. log.Init(conf.Conf.Log)
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. defer func() {
  25. log.Close()
  26. // wait for a while to guarantee that all log messages are written
  27. time.Sleep(10 * time.Millisecond)
  28. }()
  29. //service init
  30. svc := service.New(conf.Conf)
  31. http.Init(conf.Conf, svc)
  32. // init signal
  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("open-admin get a signal %s", s.String())
  38. switch s {
  39. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  40. svc.Close()
  41. return
  42. case syscall.SIGHUP:
  43. // TODO reload
  44. default:
  45. return
  46. }
  47. }
  48. }