main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/interface/main/activity/conf"
  8. "go-common/app/interface/main/activity/http"
  9. rpc "go-common/app/interface/main/activity/rpc/server"
  10. "go-common/app/interface/main/activity/service/like"
  11. ecode "go-common/library/ecode/tip"
  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. // init log
  22. log.Init(conf.Conf.Log)
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. defer log.Close()
  26. log.Info("activity start")
  27. // ecode
  28. ecode.Init(conf.Conf.Ecode)
  29. // service init
  30. svr := like.New(conf.Conf)
  31. rpcSvr := rpc.New(conf.Conf, svr)
  32. http.Init(conf.Conf)
  33. // init signal
  34. c := make(chan os.Signal, 1)
  35. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. s := <-c
  38. log.Info("activity get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  41. rpcSvr.Close()
  42. http.CloseService()
  43. log.Info("activity exit")
  44. return
  45. case syscall.SIGHUP:
  46. // TODO reload
  47. default:
  48. return
  49. }
  50. }
  51. }