main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "go-common/app/service/main/bns/agent"
  9. "go-common/app/service/main/bns/conf"
  10. "go-common/library/log"
  11. _ "go-common/app/service/main/bns/agent/backend/discovery"
  12. )
  13. var confPath string
  14. func init() {
  15. flag.StringVar(&confPath, "conf", "", "default config path")
  16. }
  17. func main() {
  18. if !flag.Parsed() {
  19. flag.Parse()
  20. }
  21. cfg, err := conf.LoadConfig(confPath)
  22. if err != nil {
  23. panic(fmt.Sprintf("loadconfig from: %s error: %s", confPath, err))
  24. }
  25. log.Init(cfg.Log)
  26. defer log.Close()
  27. ag, err := agent.New(cfg)
  28. if err != nil {
  29. panic(err)
  30. }
  31. if err := ag.Start(); err != nil {
  32. panic(err)
  33. }
  34. log.Info("bns start ...")
  35. ch := make(chan os.Signal, 1)
  36. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for s := range ch {
  38. log.Info("bns get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. log.Info("bns exit ...")
  42. return
  43. case syscall.SIGHUP:
  44. log.Warn("reload is not support yet!")
  45. default:
  46. os.Exit(1)
  47. }
  48. }
  49. }