main.go 1.1 KB

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