main.go 953 B

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