main.go 1.0 KB

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