main.go 866 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/card/conf"
  8. "go-common/app/job/main/card/server/http"
  9. "go-common/app/job/main/card/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. )
  13. func main() {
  14. flag.Parse()
  15. if err := conf.Init(); err != nil {
  16. panic(err)
  17. }
  18. log.Init(conf.Conf.Log)
  19. defer log.Close()
  20. log.Info("card-job start")
  21. trace.Init(conf.Conf.Tracer)
  22. defer trace.Close()
  23. svc := service.New(conf.Conf)
  24. http.Init(conf.Conf, svc)
  25. c := make(chan os.Signal, 1)
  26. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  27. for {
  28. s := <-c
  29. log.Info("get a signal %s", s.String())
  30. switch s {
  31. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  32. svc.Close()
  33. log.Info("card-job exit")
  34. svc.Wait()
  35. return
  36. case syscall.SIGHUP:
  37. default:
  38. return
  39. }
  40. }
  41. }