main.go 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/main/growup/conf"
  9. "go-common/app/job/main/growup/http"
  10. "go-common/library/log"
  11. )
  12. func main() {
  13. flag.Parse()
  14. if err := conf.Init(); err != nil {
  15. panic(err)
  16. }
  17. log.Init(conf.Conf.Log)
  18. log.Info("growup-job start")
  19. http.Init(conf.Conf)
  20. signalHandler()
  21. }
  22. func signalHandler() {
  23. var ch = make(chan os.Signal, 1)
  24. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  25. for {
  26. si := <-ch
  27. log.Info("growup-job get a signal %s", si.String())
  28. switch si {
  29. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  30. log.Info("get a signal %s, stop the consume process", si.String())
  31. log.Info("growup-job [verison: %s] exit")
  32. http.Close()
  33. time.Sleep(time.Second)
  34. return
  35. case syscall.SIGHUP:
  36. default:
  37. return
  38. }
  39. }
  40. }