mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-05 16:17:01 +08:00
new CLI option dump-all-plugins
allows Kong to know which plugins are manages by a specific instance of a plugin server.
This commit is contained in:
@@ -115,7 +115,6 @@ func (s *PluginServer) StartInstance(config PluginConfig, status *InstanceStatus
|
|||||||
s.instances[instance.id] = &instance
|
s.instances[instance.id] = &instance
|
||||||
|
|
||||||
plug.lastStartInstance = instance.startTime
|
plug.lastStartInstance = instance.startTime
|
||||||
s.expireInstances()
|
|
||||||
|
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
|
|
||||||
|
37
main.go
37
main.go
@@ -10,8 +10,11 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +24,7 @@ var version = "development"
|
|||||||
var (
|
var (
|
||||||
kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)")
|
kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)")
|
||||||
dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object")
|
dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object")
|
||||||
|
dumpAllPlugins = flag.Bool("dump-all-plugins", false, "Dump info about all available plugins")
|
||||||
pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins")
|
pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins")
|
||||||
showVersion = flag.Bool("version", false, "Print binary and runtime version")
|
showVersion = flag.Bool("version", false, "Print binary and runtime version")
|
||||||
)
|
)
|
||||||
@@ -60,6 +64,32 @@ func dumpInfo() {
|
|||||||
_ = enc.Encode(info)
|
_ = enc.Encode(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dumpAll() {
|
||||||
|
s := newServer()
|
||||||
|
|
||||||
|
pluginPaths, err := filepath.Glob(path.Join(s.pluginsDir, "/*.so"))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("can't get plugin names from %s: %s", s.pluginsDir, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
infos := make([]PluginInfo, len(pluginPaths))
|
||||||
|
|
||||||
|
for i, pluginPath := range pluginPaths {
|
||||||
|
pluginName := strings.TrimSuffix(path.Base(pluginPath), ".so")
|
||||||
|
|
||||||
|
err = s.GetPluginInfo(pluginName, &infos[i])
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("can't load Plugin %s: %s", pluginName, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var handle codec.JsonHandle
|
||||||
|
enc := codec.NewEncoder(os.Stdout, &handle)
|
||||||
|
_ = enc.Encode(infos)
|
||||||
|
}
|
||||||
|
|
||||||
func runServer(listener net.Listener) {
|
func runServer(listener net.Listener) {
|
||||||
var handle codec.MsgpackHandle
|
var handle codec.MsgpackHandle
|
||||||
handle.ReaderBufferSize = 4096
|
handle.ReaderBufferSize = 4096
|
||||||
@@ -70,7 +100,6 @@ func runServer(listener net.Listener) {
|
|||||||
for {
|
for {
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("accept(): %s", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +125,6 @@ func startServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rpc.RegisterName("plugin", newServer())
|
rpc.RegisterName("plugin", newServer())
|
||||||
|
|
||||||
runServer(listener)
|
runServer(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +143,11 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *dumpAllPlugins {
|
||||||
|
dumpAll()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if socket != "" {
|
if socket != "" {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user