main.go 1.1 KB

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