main.go 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "time"
  6. "go-common/app/admin/main/spy/conf"
  7. "go-common/app/admin/main/spy/http"
  8. "go-common/app/admin/main/spy/service"
  9. "go-common/library/log"
  10. "go-common/library/os/signal"
  11. "go-common/library/syscall"
  12. )
  13. var (
  14. s *service.Service
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(); err != nil {
  19. log.Error("conf.Init() error(%v)", err)
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. // service init
  25. http.Init(conf.Conf)
  26. log.Info("spy-admin start")
  27. signalHandler()
  28. }
  29. func signalHandler() {
  30. var (
  31. ch = make(chan os.Signal, 1)
  32. )
  33. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP)
  34. for {
  35. si := <-ch
  36. switch si {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  38. time.Sleep(time.Second * 2)
  39. log.Info("get a signal %s, stop the spy-admin process", si.String())
  40. s.Wait()
  41. time.Sleep(time.Second)
  42. return
  43. case syscall.SIGHUP:
  44. default:
  45. return
  46. }
  47. }
  48. }