main.go 876 B

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