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/ep/melloi/conf"
  9. "go-common/app/admin/ep/melloi/http"
  10. "go-common/app/admin/ep/melloi/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. )
  14. const (
  15. _durationForClosingServer = 2000
  16. )
  17. func main() {
  18. flag.Parse()
  19. if err := conf.Init(); err != nil {
  20. log.Error("conf.Init() error(%v)", err)
  21. panic(err)
  22. }
  23. // init log
  24. log.Init(conf.Conf.Log)
  25. defer log.Close()
  26. log.Info("melloi start")
  27. // ecode init
  28. ecode.Init(conf.Conf.Ecode)
  29. // service init
  30. s := service.New(conf.Conf)
  31. http.Init(conf.Conf, s)
  32. // init pprof conf.Conf.Perf
  33. // init signal
  34. c := make(chan os.Signal, 1)
  35. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. si := <-c
  38. log.Info("melloi get a signal %s", si.String())
  39. switch si {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. log.Info("melloi exit")
  42. s.Close()
  43. time.Sleep(_durationForClosingServer)
  44. return
  45. case syscall.SIGHUP:
  46. default:
  47. return
  48. }
  49. }
  50. }