diff --git a/builtin/bins/dkron-executor-shell/main.go b/builtin/bins/dkron-executor-shell/main.go deleted file mode 100644 index fb22bcc78..000000000 --- a/builtin/bins/dkron-executor-shell/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - dkplugin "github.com/distribworks/dkron/v3/plugin" - "github.com/hashicorp/go-plugin" -) - -func main() { - plugin.Serve(&plugin.ServeConfig{ - HandshakeConfig: dkplugin.Handshake, - Plugins: map[string]plugin.Plugin{ - "executor": &dkplugin.ExecutorPlugin{Executor: &Shell{}}, - }, - - // A non-nil value here enables gRPC serving for this plugin... - GRPCServer: plugin.DefaultGRPCServer, - }) -} diff --git a/cmd/plugins.go b/cmd/plugins.go index 772d99bb4..fe4d2a777 100644 --- a/cmd/plugins.go +++ b/cmd/plugins.go @@ -64,13 +64,12 @@ func (p *Plugins) DiscoverPlugins() error { } for _, file := range processors { - pluginName, ok := getPluginName(file) if !ok { continue } - raw, err := p.pluginFactory(file, dkplugin.ProcessorPluginName) + raw, err := p.pluginFactory(file, []string{}, dkplugin.ProcessorPluginName) if err != nil { return err } @@ -78,19 +77,24 @@ func (p *Plugins) DiscoverPlugins() error { } for _, file := range executors { - pluginName, ok := getPluginName(file) if !ok { continue } - raw, err := p.pluginFactory(file, dkplugin.ExecutorPluginName) + raw, err := p.pluginFactory(file, []string{}, dkplugin.ExecutorPluginName) if err != nil { return err } p.Executors[pluginName] = raw.(dkplugin.Executor) } + raw, err := p.pluginFactory(exePath, []string{"shell"}, dkplugin.ExecutorPluginName) + if err != nil { + return err + } + p.Executors["shell"] = raw.(dkplugin.Executor) + return nil } @@ -107,10 +111,10 @@ func getPluginName(file string) (string, bool) { return name, true } -func (p *Plugins) pluginFactory(path string, pluginType string) (interface{}, error) { +func (p *Plugins) pluginFactory(path string, args []string, pluginType string) (interface{}, error) { // Build the plugin client configuration and init the plugin var config plugin.ClientConfig - config.Cmd = exec.Command(path) + config.Cmd = exec.Command(path, args...) config.HandshakeConfig = dkplugin.Handshake config.Managed = true config.Plugins = dkplugin.PluginMap diff --git a/cmd/shell.go b/cmd/shell.go new file mode 100644 index 000000000..f02c5f5fb --- /dev/null +++ b/cmd/shell.go @@ -0,0 +1,27 @@ +package cmd + +import ( + dkplugin "github.com/distribworks/dkron/v3/plugin" + "github.com/distribworks/dkron/v3/plugin/shell" + "github.com/hashicorp/go-plugin" + "github.com/spf13/cobra" +) + +var shellCmd = &cobra.Command{ + Hidden: true, + Run: func(cmd *cobra.Command, args []string) { + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: dkplugin.Handshake, + Plugins: map[string]plugin.Plugin{ + "executor": &dkplugin.ExecutorPlugin{Executor: &shell.Shell{}}, + }, + + // A non-nil value here enables gRPC serving for this plugin... + GRPCServer: plugin.DefaultGRPCServer, + }) + }, +} + +func init() { + dkronCmd.AddCommand(shellCmd) +} diff --git a/builtin/bins/dkron-executor-shell/shell.go b/plugin/shell/shell.go similarity index 99% rename from builtin/bins/dkron-executor-shell/shell.go rename to plugin/shell/shell.go index 3d4da4bef..d09cc90a6 100644 --- a/builtin/bins/dkron-executor-shell/shell.go +++ b/plugin/shell/shell.go @@ -1,4 +1,4 @@ -package main +package shell import ( "encoding/base64" diff --git a/builtin/bins/dkron-executor-shell/shell_test.go b/plugin/shell/shell_test.go similarity index 98% rename from builtin/bins/dkron-executor-shell/shell_test.go rename to plugin/shell/shell_test.go index 039077564..16c155d0c 100644 --- a/builtin/bins/dkron-executor-shell/shell_test.go +++ b/plugin/shell/shell_test.go @@ -1,4 +1,4 @@ -package main +package shell import ( "os" diff --git a/builtin/bins/dkron-executor-shell/shell_unix.go b/plugin/shell/shell_unix.go similarity index 97% rename from builtin/bins/dkron-executor-shell/shell_unix.go rename to plugin/shell/shell_unix.go index c3731163a..db11cc182 100644 --- a/builtin/bins/dkron-executor-shell/shell_unix.go +++ b/plugin/shell/shell_unix.go @@ -1,6 +1,6 @@ // +build !windows -package main +package shell import ( "os/exec" diff --git a/builtin/bins/dkron-executor-shell/shell_windows.go b/plugin/shell/shell_windows.go similarity index 89% rename from builtin/bins/dkron-executor-shell/shell_windows.go rename to plugin/shell/shell_windows.go index 417de4030..104dfbd16 100644 --- a/builtin/bins/dkron-executor-shell/shell_windows.go +++ b/plugin/shell/shell_windows.go @@ -1,6 +1,6 @@ // +build windows -package main +package shell import ( "os/exec"