mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 18:10:26 +08:00
增加 edge-node reload 命令/优化命令行帮助
This commit is contained in:
@@ -22,7 +22,9 @@ func main() {
|
|||||||
app := apps.NewAppCmd().
|
app := apps.NewAppCmd().
|
||||||
Version(teaconst.Version).
|
Version(teaconst.Version).
|
||||||
Product(teaconst.ProductName).
|
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() {
|
app.On("test", func() {
|
||||||
err := nodes.NewNode().Test()
|
err := nodes.NewNode().Test()
|
||||||
@@ -30,6 +32,20 @@ func main() {
|
|||||||
_, _ = os.Stderr.WriteString(err.Error())
|
_, _ = 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() {
|
app.On("daemon", func() {
|
||||||
nodes.NewNode().Daemon()
|
nodes.NewNode().Daemon()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
type AppCmd struct {
|
type AppCmd struct {
|
||||||
product string
|
product string
|
||||||
version string
|
version string
|
||||||
usage string
|
usages []string
|
||||||
options []*CommandHelpOption
|
options []*CommandHelpOption
|
||||||
appendStrings []string
|
appendStrings []string
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ func (this *AppCmd) Version(version string) *AppCmd {
|
|||||||
|
|
||||||
// Usage 使用方法
|
// Usage 使用方法
|
||||||
func (this *AppCmd) Usage(usage string) *AppCmd {
|
func (this *AppCmd) Usage(usage string) *AppCmd {
|
||||||
this.usage = usage
|
this.usages = append(this.usages, usage)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +77,10 @@ func (this *AppCmd) Append(appendString string) *AppCmd {
|
|||||||
func (this *AppCmd) Print() {
|
func (this *AppCmd) Print() {
|
||||||
fmt.Println(this.product + " v" + this.version)
|
fmt.Println(this.product + " v" + this.version)
|
||||||
|
|
||||||
usage := this.usage
|
fmt.Println("Usage:")
|
||||||
fmt.Println("Usage:", "\n "+usage)
|
for _, usage := range this.usages {
|
||||||
|
fmt.Println(" " + usage)
|
||||||
|
}
|
||||||
|
|
||||||
if len(this.options) > 0 {
|
if len(this.options) > 0 {
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
|||||||
@@ -742,6 +742,17 @@ func (this *Node) listenSock() error {
|
|||||||
runtime.GC()
|
runtime.GC()
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
_ = cmd.ReplyOk()
|
_ = 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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user