Merge pull request #14297 from hashicorp/b-logmon-fork-mystery-bin

client/logmon: acquire executable in init block
This commit is contained in:
Seth Hoenig 2022-08-24 15:25:09 -05:00 committed by GitHub
commit 5e18c7b5b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

3
.changelog/14297.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
client/logmon: fixed a bug where logmon cannot find nomad executable
```

View File

@ -5,22 +5,27 @@ import (
"os"
"os/exec"
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/client/logmon/proto"
"github.com/hashicorp/nomad/plugins/base"
"google.golang.org/grpc"
)
var bin = getBin()
func getBin() string {
b, err := os.Executable()
if err != nil {
panic(err)
}
return b
}
// LaunchLogMon launches a new logmon or reattaches to an existing one.
// TODO: Integrate with base plugin loader
func LaunchLogMon(logger hclog.Logger, reattachConfig *plugin.ReattachConfig) (LogMon, *plugin.Client, error) {
logger = logger.Named("logmon")
bin, err := os.Executable()
if err != nil {
return nil, nil, err
}
conf := &plugin.ClientConfig{
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{