main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/up/conf"
  9. "go-common/app/admin/main/up/http"
  10. "go-common/library/log"
  11. manager "go-common/library/queue/databus/report"
  12. )
  13. func main() {
  14. flag.Parse()
  15. if err := conf.Init(); err != nil {
  16. log.Error("conf.Init() error(%v)", err)
  17. panic(err)
  18. }
  19. // init log
  20. log.Init(conf.Conf.XLog)
  21. defer log.Close()
  22. log.SetFormat("[%D %T] [%L] [%S] %M")
  23. log.Info("up-adminstart")
  24. // service init
  25. http.Init(conf.Conf)
  26. //logCli.Init(conf.Conf.LogCli)
  27. // manager log init
  28. manager.InitManager(nil)
  29. // init signal
  30. c := make(chan os.Signal, 1)
  31. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  32. for {
  33. s := <-c
  34. log.Info("up-admin get a signal %s", s.String())
  35. switch s {
  36. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  37. http.Svc.Close()
  38. log.Info("up-adminexit")
  39. time.Sleep(1 * time.Second)
  40. return
  41. case syscall.SIGHUP:
  42. // TODO reload
  43. default:
  44. return
  45. }
  46. }
  47. }