Skip to content

Commit

Permalink
[Ingest Manager] Use symlink path for reexecutions (#21835) (#22099)
Browse files Browse the repository at this point in the history
[Ingest Manager] Use symlink path for reexecutions (#21835)
  • Loading branch information
michalpristas committed Oct 22, 2020
1 parent 62538ff commit b19041a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Include inputs in action store actions {pull}21298[21298]
- Fix issue where inputs without processors defined would panic {pull}21628[21628]
- Partial extracted beat result in failure to spawn beat {issue}21718[21718]
- Use symlink path for reexecutions {pull}21835[21835]
- Use ML_SYSTEM to detect if agent is running as a service {pull}21884[21884]
- Use local temp instead of system one {pull}21883[21883]
- Fix issue with named pipes on Windows 7 {pull}21931[21931]
Expand Down
20 changes: 19 additions & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/spf13/cobra"
Expand All @@ -26,6 +27,10 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
)

const (
agentName = "elastic-agent"
)

func newRunCommandWithArgs(flags *globalFlags, _ []string, streams *cli.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "run",
Expand Down Expand Up @@ -87,7 +92,7 @@ func run(flags *globalFlags, streams *cli.IOStreams) error { // Windows: Mark se
logger.Warn("Artifact has been build with security disabled. Elastic Agent will not verify signatures of used artifacts.")
}

execPath, err := os.Executable()
execPath, err := reexecPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -146,3 +151,16 @@ func run(flags *globalFlags, streams *cli.IOStreams) error { // Windows: Mark se
rex.ShutdownComplete()
return err
}

func reexecPath() (string, error) {
// set executable path to symlink instead of binary
// in case of updated symlinks we should spin up new agent
potentialReexec := filepath.Join(paths.Top(), agentName)

// in case it does not exists fallback to executable
if _, err := os.Stat(potentialReexec); os.IsNotExist(err) {
return os.Executable()
}

return potentialReexec, nil
}

0 comments on commit b19041a

Please sign in to comment.