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/antispam/conf"
  9. "go-common/app/service/main/antispam/http"
  10. rpc "go-common/app/service/main/antispam/rpc/server"
  11. "go-common/app/service/main/antispam/service"
  12. ecode "go-common/library/ecode/tip"
  13. "go-common/library/log"
  14. "go-common/library/net/trace"
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(conf.ConfPath); err != nil {
  19. panic(err)
  20. }
  21. log.Init(conf.Conf.Log)
  22. ecode.Init(conf.Conf.Ecode)
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. defer log.Close()
  26. log.Info("antispam start")
  27. svr := service.New(conf.Conf)
  28. rpcSvr := rpc.New(conf.Conf, svr)
  29. http.Init(conf.Conf, svr)
  30. // init signal
  31. ch := make(chan os.Signal, 1)
  32. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  33. for {
  34. si := <-ch
  35. switch si {
  36. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  37. log.Info("get a signal %s, stop the consume process", si.String())
  38. rpcSvr.Close()
  39. time.Sleep(time.Second * 2)
  40. svr.Close()
  41. return
  42. case syscall.SIGHUP:
  43. default:
  44. return
  45. }
  46. }
  47. }