From 24a1c48f470885a245212247eac3c1d576d65b1f Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 24 Aug 2022 13:07:31 -0500 Subject: [PATCH] client/logmon: acquire executable in init block This PR causes the logmon task runner to acquire the binary of the Nomad executable in an 'init' block, so as to almost certainly get the name while the nomad file still exists. This is an attempt at fixing the case where a deleted Nomad file (e.g. during upgrade) may be getting renamed with a mysterious suffix first. If this doesn't work, as a last resort we can literally just trim the mystery string. Fixes: #14079 --- .changelog/14297.txt | 3 +++ client/logmon/plugin.go | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .changelog/14297.txt diff --git a/.changelog/14297.txt b/.changelog/14297.txt new file mode 100644 index 000000000000..207eb3858901 --- /dev/null +++ b/.changelog/14297.txt @@ -0,0 +1,3 @@ +```release-note:bug +client/logmon: fixed a bug where logmon cannot find nomad executable +``` diff --git a/client/logmon/plugin.go b/client/logmon/plugin.go index 5d97b751d104..a21777357cb0 100644 --- a/client/logmon/plugin.go +++ b/client/logmon/plugin.go @@ -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{