main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/bbq/recall/internal/conf"
  9. "go-common/app/job/bbq/recall/internal/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. )
  13. var (
  14. _serviceName string
  15. )
  16. func init() {
  17. flag.StringVar(&_serviceName, "service", "", "run service name")
  18. }
  19. func main() {
  20. flag.Parse()
  21. if err := conf.Init(); err != nil {
  22. panic(err)
  23. }
  24. log.Init(conf.Conf.Log)
  25. defer log.Close()
  26. log.Info("recall-job start")
  27. trace.Init(conf.Conf.Tracer)
  28. defer trace.Close()
  29. svc := service.New(conf.Conf)
  30. defer svc.Close()
  31. if _serviceName != "" {
  32. svc.RunSrv(_serviceName)
  33. } else {
  34. svc.InitCron()
  35. deamon()
  36. }
  37. }
  38. func deamon() {
  39. c := make(chan os.Signal, 1)
  40. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  41. for {
  42. s := <-c
  43. log.Info("get a signal %s", s.String())
  44. switch s {
  45. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  46. log.Info("recall-job exit")
  47. time.Sleep(time.Second)
  48. return
  49. case syscall.SIGHUP:
  50. default:
  51. return
  52. }
  53. }
  54. }