main.go 928 B

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