diff --git a/cmd/edge-node/main.go b/cmd/edge-node/main.go index 8dfedd5..4387c14 100644 --- a/cmd/edge-node/main.go +++ b/cmd/edge-node/main.go @@ -22,7 +22,9 @@ func main() { app := apps.NewAppCmd(). Version(teaconst.Version). Product(teaconst.ProductName). - Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|service|daemon|pprof]") + Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|pprof]"). + Usage(teaconst.ProcessName + " [trackers|goman|conns|gc]"). + Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove] IP") app.On("test", func() { err := nodes.NewNode().Test() @@ -30,6 +32,20 @@ func main() { _, _ = os.Stderr.WriteString(err.Error()) } }) + app.On("reload", func() { + var sock = gosock.NewTmpSock(teaconst.ProcessName) + reply, err := sock.Send(&gosock.Command{Code: "reload"}) + if err != nil { + fmt.Println("[ERROR]" + err.Error()) + } else { + var params = maps.NewMap(reply.Params) + if params.Has("error") { + fmt.Println("[ERROR]" + params.GetString("error")) + } else { + fmt.Println("ok") + } + } + }) app.On("daemon", func() { nodes.NewNode().Daemon() }) diff --git a/internal/apps/app_cmd.go b/internal/apps/app_cmd.go index 9da4136..7c67a66 100644 --- a/internal/apps/app_cmd.go +++ b/internal/apps/app_cmd.go @@ -20,7 +20,7 @@ import ( type AppCmd struct { product string version string - usage string + usages []string options []*CommandHelpOption appendStrings []string @@ -54,7 +54,7 @@ func (this *AppCmd) Version(version string) *AppCmd { // Usage 使用方法 func (this *AppCmd) Usage(usage string) *AppCmd { - this.usage = usage + this.usages = append(this.usages, usage) return this } @@ -77,8 +77,10 @@ func (this *AppCmd) Append(appendString string) *AppCmd { func (this *AppCmd) Print() { fmt.Println(this.product + " v" + this.version) - usage := this.usage - fmt.Println("Usage:", "\n "+usage) + fmt.Println("Usage:") + for _, usage := range this.usages { + fmt.Println(" " + usage) + } if len(this.options) > 0 { fmt.Println("") diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 12e14fe..4d69f7c 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -742,6 +742,17 @@ func (this *Node) listenSock() error { runtime.GC() debug.FreeOSMemory() _ = cmd.ReplyOk() + case "reload": + err := this.syncConfig(0) + if err != nil { + _ = cmd.Reply(&gosock.Command{ + Params: map[string]interface{}{ + "error": err.Error(), + }, + }) + } else { + _ = cmd.ReplyOk() + } } })