main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/admin/main/usersuit/conf"
  8. "go-common/app/admin/main/usersuit/http"
  9. "go-common/app/admin/main/usersuit/service"
  10. ecode "go-common/library/ecode/tip"
  11. "go-common/library/log"
  12. "go-common/library/net/trace"
  13. )
  14. func main() {
  15. flag.Parse()
  16. // init conf,log,trace,stat,perf.
  17. if err := conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Log)
  21. defer log.Close()
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. // service init
  25. svr := service.New(conf.Conf)
  26. http.Init(conf.Conf, svr)
  27. // service init
  28. ecode.Init(conf.Conf.Ecode)
  29. // signal handler
  30. log.Info("usersuit-admin start")
  31. c := make(chan os.Signal, 1)
  32. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  33. for {
  34. s := <-c
  35. log.Info("usersuit-admin get a signal %s", s.String())
  36. switch s {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  38. svr.Close()
  39. log.Info("usersuit-admin exit")
  40. return
  41. case syscall.SIGHUP:
  42. // TODO reload
  43. default:
  44. return
  45. }
  46. }
  47. }