-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Elastic Agent] Improve version, restart, enroll CLI commands #20359
Changes from 8 commits
24b9afd
d659548
9121ac5
2320250
8e24d02
93d6fb1
85e0d89
ac69b87
a7b0d3c
a334253
a8d00aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,19 @@ type ExecManager interface { | |
ShutdownComplete() | ||
} | ||
|
||
// Manager returns the global reexec manager. | ||
func Manager(log *logger.Logger, exec string) ExecManager { | ||
// NewManager returns the global reexec manager. | ||
func NewManager(log *logger.Logger, exec string) ExecManager { | ||
execSingletonOnce.Do(func() { | ||
execSingleton = newManager(log, exec) | ||
}) | ||
return execSingleton | ||
} | ||
|
||
// Manager returns the global reexec manager. | ||
func Manager() ExecManager { | ||
return execSingleton | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not look like a good idea why not having just one method with Once-initialization There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to, but that deep into the code, I didn't want to have to pass in the logger and the path to the executable. I wanted that to be set at startup and later usages of the manager, can get the singleton. |
||
} | ||
|
||
type manager struct { | ||
logger *logger.Logger | ||
exec string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,14 @@ | |
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/client" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/backoff" | ||
|
@@ -45,6 +48,7 @@ func newEnrollCommandWithArgs(flags *globalFlags, _ []string, streams *cli.IOStr | |
cmd.Flags().BoolP("force", "f", false, "Force overwrite the current and do not prompt for confirmation") | ||
cmd.Flags().BoolP("insecure", "i", false, "Allow insecure connection to Kibana") | ||
cmd.Flags().StringP("staging", "", "", "Configures agent to download artifacts from a staging build") | ||
cmd.Flags().Bool("no-restart", false, "Skip restarting the currently running daemon") | ||
|
||
return cmd | ||
} | ||
|
@@ -144,7 +148,25 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command, flags *globalFlags, args | |
return errors.New(err, "fail to enroll") | ||
} | ||
|
||
fmt.Fprintln(streams.Out, "Successfully enrolled the Agent.") | ||
fmt.Fprintln(streams.Out, "Successfully enrolled the Elastic Agent.") | ||
|
||
// skip restarting | ||
noRestart, _ := cmd.Flags().GetBool("no-restart") | ||
if noRestart { | ||
return nil | ||
} | ||
|
||
daemon := client.New() | ||
err = daemon.Start(context.Background()) | ||
if err == nil { | ||
defer daemon.Stop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you stopping after restart is done? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this all makes sense then :-) |
||
err = daemon.Restart(context.Background()) | ||
if err == nil { | ||
fmt.Fprintln(streams.Out, "Successfully triggered restart on running Elastic Agent.") | ||
return nil | ||
} | ||
} | ||
fmt.Fprintln(streams.Out, "Elastic Agent might not be running; unable to trigger restart") | ||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need 3 entries here, they link the same pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was easier to read being 3 different things, but if you prefer it to be 1 line, I can do that.