main.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "go-common/app/job/main/figure-timer/conf"
  7. "go-common/app/job/main/figure-timer/http"
  8. "go-common/app/job/main/figure-timer/service"
  9. "go-common/library/log"
  10. "go-common/library/syscall"
  11. )
  12. var (
  13. srv *service.Service
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := conf.Init(); err != nil {
  18. log.Error("conf.Init() error(%v)", err)
  19. panic(err)
  20. }
  21. log.Init(conf.Conf.Log)
  22. defer log.Close()
  23. srv = service.New(conf.Conf)
  24. http.Init(srv)
  25. log.Info("figure-timer-job start")
  26. signalHandler()
  27. }
  28. func signalHandler() {
  29. var (
  30. ch = make(chan os.Signal, 1)
  31. )
  32. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP)
  33. for {
  34. si := <-ch
  35. log.Info("figure-timer-job got a signal (%d)", si)
  36. switch si {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  38. srv.Close()
  39. srv.Wait()
  40. log.Info("figure-timer-job exit")
  41. return
  42. case syscall.SIGHUP:
  43. default:
  44. return
  45. }
  46. }
  47. }