main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "time"
  6. "go-common/app/admin/main/activity/conf"
  7. "go-common/app/admin/main/activity/http"
  8. "go-common/app/admin/main/activity/service"
  9. "go-common/library/log"
  10. "go-common/library/net/trace"
  11. "go-common/library/os/signal"
  12. "go-common/library/syscall"
  13. )
  14. var (
  15. s *service.Service
  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. log.Init(conf.Conf.Log)
  24. defer log.Close()
  25. trace.Init(conf.Conf.Tracer)
  26. defer trace.Close()
  27. s = service.New(conf.Conf)
  28. http.Init(conf.Conf, s)
  29. log.Info("push-admin start")
  30. signalHandler()
  31. }
  32. func signalHandler() {
  33. var (
  34. ch = make(chan os.Signal, 1)
  35. )
  36. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. si := <-ch
  39. switch si {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  41. time.Sleep(time.Second * 2)
  42. log.Info("get a signal %s, stop the push-admin process", si.String())
  43. s.Close()
  44. s.Wait()
  45. time.Sleep(time.Second)
  46. return
  47. case syscall.SIGHUP:
  48. default:
  49. return
  50. }
  51. }
  52. }