main.go 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/main/push/conf"
  9. "go-common/app/job/main/push/http"
  10. "go-common/app/job/main/push/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. panic(err)
  18. }
  19. log.Init(conf.Conf.Log)
  20. defer log.Close()
  21. trace.Init(conf.Conf.Tracer)
  22. defer trace.Close()
  23. log.Info("push-job start")
  24. svc := service.New(conf.Conf)
  25. http.Init(conf.Conf, svc)
  26. listenSignals(svc)
  27. }
  28. func listenSignals(svc *service.Service) {
  29. c := make(chan os.Signal, 1)
  30. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  31. for {
  32. s := <-c
  33. log.Info("push-job get a signal: %s", s.String())
  34. switch s {
  35. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  36. svc.Close()
  37. log.Info("push-job stop")
  38. time.Sleep(time.Second)
  39. return
  40. case syscall.SIGHUP:
  41. // TODO: reload
  42. default:
  43. return
  44. }
  45. }
  46. }