main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "os"
  6. "go-common/app/service/main/dapper/agent"
  7. "go-common/app/service/main/dapper/conf"
  8. "go-common/app/service/main/dapper/pkg/util"
  9. xlog "go-common/library/log"
  10. )
  11. var debug bool
  12. func init() {
  13. flag.BoolVar(&debug, "debug", false, "debug model decode and print span on stdout")
  14. }
  15. func main() {
  16. if !flag.Parsed() {
  17. flag.Parse()
  18. }
  19. cfg, err := conf.LoadAgentConfig()
  20. if err != nil {
  21. log.Fatalf("local agent config error: %s", err)
  22. }
  23. xlog.Init(cfg.Log)
  24. defer xlog.Close()
  25. ag, err := agent.New(cfg, debug)
  26. if err != nil {
  27. log.Fatalf("new agent service error: %s", err)
  28. }
  29. util.HandlerReload(func(s os.Signal) {
  30. xlog.Warn("receive signal %s, dapper agent reload config", s)
  31. cfg, err := conf.LoadAgentConfig()
  32. if err != nil {
  33. xlog.Error("load config error: %s, reload config fail!", err)
  34. return
  35. }
  36. if err := ag.Reload(cfg); err != nil {
  37. xlog.Error("reload config error: %s", err)
  38. }
  39. })
  40. util.HandlerExit(func(s os.Signal) int {
  41. if err := ag.Close(); err != nil {
  42. xlog.Error("close agent error: %s", err)
  43. return 1
  44. }
  45. return 0
  46. })
  47. }