main.go 915 B

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