main.go 1.2 KB

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