main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/appstatic/conf"
  8. "go-common/app/job/main/appstatic/http"
  9. "go-common/app/job/main/appstatic/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. trace.Init(conf.Conf.Tracer)
  20. defer trace.Close()
  21. defer log.Close()
  22. log.Info("appstatic-job start")
  23. srv := service.New(conf.Conf)
  24. http.Init(conf.Conf, srv)
  25. initSignal(srv)
  26. }
  27. func initSignal(srv *service.Service) {
  28. c := make(chan os.Signal, 1)
  29. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  30. for {
  31. s := <-c
  32. log.Info("appstatic-job get a signal: %s", s.String())
  33. switch s {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  35. if err := srv.Close(); err != nil {
  36. log.Error("srv close consumer error(%v)", err)
  37. }
  38. return
  39. case syscall.SIGHUP:
  40. // TODO: reload
  41. default:
  42. return
  43. }
  44. }
  45. }