Notify handler for cmds from admin
(command string)
| 44 | |
| 45 | // Notify handler for cmds from admin |
| 46 | func (a *Admin) Notify(command string) (string, error) { |
| 47 | cmd := strings.Split(command, " ") |
| 48 | // report command to notify |
| 49 | go ReportNotifyInfo(NotifyNormal, "AdminServant::notify:"+command) |
| 50 | switch cmd[0] { |
| 51 | case "tars.viewversion": |
| 52 | return a.app.ServerConfig().Version, nil |
| 53 | case "tars.setloglevel": |
| 54 | if len(cmd) >= 2 { |
| 55 | a.app.appCache.LogLevel = cmd[1] |
| 56 | switch cmd[1] { |
| 57 | case "INFO": |
| 58 | rogger.SetLevel(rogger.INFO) |
| 59 | case "WARN": |
| 60 | rogger.SetLevel(rogger.WARN) |
| 61 | case "ERROR": |
| 62 | rogger.SetLevel(rogger.ERROR) |
| 63 | case "DEBUG": |
| 64 | rogger.SetLevel(rogger.DEBUG) |
| 65 | case "NONE": |
| 66 | rogger.SetLevel(rogger.OFF) |
| 67 | default: |
| 68 | return fmt.Sprintf("%s failed: unknown log level [%s]!", cmd[0], cmd[1]), nil |
| 69 | } |
| 70 | return fmt.Sprintf("%s succ", command), nil |
| 71 | } |
| 72 | return fmt.Sprintf("%s failed: missing loglevel!", command), nil |
| 73 | case "tars.dumpstack": |
| 74 | debug.DumpStack(true, "stackinfo", "tars.dumpstack:") |
| 75 | return fmt.Sprintf("%s succ", command), nil |
| 76 | case "tars.loadconfig": |
| 77 | cfg := a.app.ServerConfig() |
| 78 | remoteConf := NewRConf(cfg.App, cfg.Server, cfg.BasePath) |
| 79 | _, err := remoteConf.GetConfig(cmd[1]) |
| 80 | if err != nil { |
| 81 | return fmt.Sprintf("Getconfig Error!: %s", cmd[1]), err |
| 82 | } |
| 83 | return fmt.Sprintf("Getconfig Success!: %s", cmd[1]), nil |
| 84 | case "tars.connection": |
| 85 | return fmt.Sprintf("%s not support now!", command), nil |
| 86 | case "tars.gracerestart": |
| 87 | a.app.graceRestart() |
| 88 | return "restart gracefully!", nil |
| 89 | case "tars.pprof": |
| 90 | port := ":8080" |
| 91 | timeout := time.Second * 600 |
| 92 | if len(cmd) > 1 { |
| 93 | port = ":" + cmd[1] |
| 94 | } |
| 95 | if len(cmd) > 2 { |
| 96 | t, _ := strconv.ParseInt(cmd[2], 10, 64) |
| 97 | if 0 < t && t < 3600 { |
| 98 | timeout = time.Second * time.Duration(t) |
| 99 | } |
| 100 | } |
| 101 | cfg := a.app.ServerConfig() |
| 102 | addr := cfg.LocalIP + port |
| 103 | go func() { |
nothing calls this directly
no test coverage detected