mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 05:29:30 +00:00
Add Agent.actions. Make pqd warn if resume file does not exist. Print which services have been added, removed, and updated.
This commit is contained in:
86
bin/pt-agent
86
bin/pt-agent
@@ -1272,6 +1272,12 @@ has 'versions' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has 'actions' => (
|
||||
is => 'ro',
|
||||
isa => 'Maybe[ArrayRef]',
|
||||
requierd => 0,
|
||||
);
|
||||
|
||||
has 'links' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[HashRef]',
|
||||
@@ -4891,8 +4897,10 @@ sub main {
|
||||
_err("$config_file exists but is not writable")
|
||||
if -f $config_file && !-w $config_file;
|
||||
|
||||
# Run the agent's main loop which doesn't return until the service
|
||||
# is stopped, killed, or has an internal bug.
|
||||
# Start, i.e. init/create/update, the agent. This forks and daemonizes,
|
||||
# so we're the child/daemon process when it returns. To remember how
|
||||
# this differs from run_agent(): first you start a car, then you put it
|
||||
# in drive to "run" (drive) it.
|
||||
my $running = start_agent(
|
||||
api_key => $api_key,
|
||||
Cxn => $cxn,
|
||||
@@ -4916,6 +4924,8 @@ sub main {
|
||||
sleep $t;
|
||||
};
|
||||
|
||||
# Run the agent's main loop which doesn't return until the service
|
||||
# is stopped, killed, or has an internal bug.
|
||||
run_agent(
|
||||
agent => $running->{agent},
|
||||
client => $running->{client},
|
||||
@@ -5044,6 +5054,7 @@ sub init_agent {
|
||||
# Optional args
|
||||
my $_oktorun = $args{oktorun} || sub { return $oktorun };
|
||||
my $tries = $args{tries};
|
||||
my $actions = $args{actions};
|
||||
|
||||
# Update these attribs every time the agent is initialized.
|
||||
# Other optional attribs, like versions, are left to the caller.
|
||||
@@ -5051,6 +5062,13 @@ sub init_agent {
|
||||
$agent->{hostname} = $hostname;
|
||||
$agent->{username} = $ENV{USER} || $ENV{LOGNAME};
|
||||
|
||||
# Add agent actions, if any. Used by instal() to report the
|
||||
# MySQL user and pass created by pt-agent so PWS will add them
|
||||
# to the agent's default config.
|
||||
if ( $actions ) {
|
||||
$agent->{actions} = $actions;
|
||||
}
|
||||
|
||||
# Try forever to create/update the Agent. The tool can't
|
||||
# do anything without an Agent, so we must succeed to proceed.
|
||||
while ( $_oktorun->() && (!defined $tries || $tries--) ) {
|
||||
@@ -5168,6 +5186,7 @@ sub start_agent {
|
||||
my $_oktorun = $args{oktorun} || sub { return $oktorun };
|
||||
my $tries = $args{tries};
|
||||
my $interval = $args{interval} || sub { sleep 60; };
|
||||
my $actions = $args{actions};
|
||||
my $versions = $args{versions}; # for testing
|
||||
my $client = $args{client}; # for testing
|
||||
my $entry_links = $args{entry_links}; # for testing
|
||||
@@ -5278,13 +5297,14 @@ sub start_agent {
|
||||
|
||||
$agent = init_agent(
|
||||
agent => $agent,
|
||||
action => $action,
|
||||
action => $action, # put or post
|
||||
link => $link,
|
||||
client => $client,
|
||||
tries => $tries,
|
||||
interval => sub { sleep 60 },
|
||||
lib_dir => $lib_dir,
|
||||
oktorun => $_oktorun,
|
||||
actions => $actions, # Agent.actions
|
||||
);
|
||||
|
||||
save_agent(
|
||||
@@ -5776,6 +5796,19 @@ sub sort_services {
|
||||
@removed = grep { !exists $services->{$_->name} } values %$prev_services;
|
||||
}
|
||||
|
||||
if ( $#added ) {
|
||||
_info("Services added:\n"
|
||||
. join("\n", map { " " . $_->name } @added) . "\n");
|
||||
}
|
||||
if ( $#updated ) {
|
||||
_info("Services updated:\n"
|
||||
. join("\n", map { " " . $_->name } @updated) . "\n");
|
||||
}
|
||||
if ( $#removed ) {
|
||||
_info("Services removed:\n"
|
||||
. join("\n", map { " " . $_->name } @removed) . "\n");
|
||||
}
|
||||
|
||||
my $sorted_services = {
|
||||
services => $services,
|
||||
added => \@added,
|
||||
@@ -6805,24 +6838,6 @@ sub install {
|
||||
print "OK: API key $api_key is valid.\n";
|
||||
}
|
||||
|
||||
my $running = eval {
|
||||
start_agent(
|
||||
api_key => $api_key,
|
||||
lib_dir => $o->get('lib'),
|
||||
Cxn => $cxn,
|
||||
client => $client,
|
||||
entry_links => $entry_links,
|
||||
agent_uuid => $o->get('agent-uuid'),
|
||||
daemonize => 0,
|
||||
pid_file => undef,
|
||||
log_file => undef,
|
||||
interval => sub { sleep 2; },
|
||||
tries => 3,
|
||||
);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
die "Sorry, an error occurred while starting the agent: $EVAL_ERROR";
|
||||
}
|
||||
|
||||
print "Creating a MySQL user for pt-agent...\n";
|
||||
my $random_pass = pseudo_random_password();
|
||||
@@ -6858,6 +6873,35 @@ pass=$random_pass
|
||||
. $EVAL_ERROR;
|
||||
}
|
||||
|
||||
# Start, i.e. init/create the agent, but don't run it yet. Normally
|
||||
# this forks in anticipation of run_agent() being called next, but
|
||||
# we don't do this during install; we run the agent manually later.
|
||||
my $running = eval {
|
||||
start_agent(
|
||||
api_key => $api_key,
|
||||
lib_dir => $o->get('lib'),
|
||||
Cxn => $cxn,
|
||||
client => $client,
|
||||
entry_links => $entry_links,
|
||||
agent_uuid => $o->get('agent-uuid'),
|
||||
daemonize => 0,
|
||||
pid_file => undef,
|
||||
log_file => undef,
|
||||
interval => sub { sleep 2; },
|
||||
tries => 3,
|
||||
#actions => [
|
||||
# "install-agent",
|
||||
# "init-config-file: $config_file",
|
||||
# "init-spool-dir: " . $o->get('spool'),
|
||||
# "init-lib-dir: " . $o->get('lib'),
|
||||
# "create-mysql-user: pt_agent,$random_pass",
|
||||
#],
|
||||
);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
die "Sorry, an error occurred while starting the agent: $EVAL_ERROR";
|
||||
}
|
||||
|
||||
print "Starting pt-agent...\n";
|
||||
my $env = env_vars();
|
||||
my $cmd = "$env $FindBin::Bin/pt-agent --daemonize";
|
||||
|
@@ -12783,8 +12783,8 @@ sub main {
|
||||
seek $fh, $resume_offset, 0
|
||||
or die "Error seeking to $resume_offset in "
|
||||
. "$resume_file: $OS_ERROR";
|
||||
warn "Resuming $filename from offset $resume_offset "
|
||||
. "(file size: $filesize)...\n";
|
||||
warn "# Resuming $filename from offset "
|
||||
. "$resume_offset (file size: $filesize)...\n";
|
||||
}
|
||||
else {
|
||||
$resume->{simple} = 0; # enhanced resume file
|
||||
@@ -12815,7 +12815,7 @@ sub main {
|
||||
seek $fh, $resume_offset, 0
|
||||
or die "Error seeking to $resume_offset in "
|
||||
. "$resume_file: $OS_ERROR";
|
||||
warn "Resuming $filename from offset "
|
||||
warn "# Resuming $filename from offset "
|
||||
. "$resume_offset to "
|
||||
. ($resume->{end_offset} ? $resume->{end_offset}
|
||||
: "end of file")
|
||||
@@ -12824,8 +12824,9 @@ sub main {
|
||||
}
|
||||
}
|
||||
else {
|
||||
PTDEBUG && _d('Not resuming', $filename, 'because',
|
||||
$resume_file, 'does not exist');
|
||||
warn "# Resuming $filename from offset 0 because "
|
||||
. "resume file $filename does not exist "
|
||||
. "(file size: $filesize)...\n";
|
||||
$resume->{simple} = 0;
|
||||
$resume->{start_offset} = 0;
|
||||
}
|
||||
|
@@ -57,6 +57,12 @@ has 'versions' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has 'actions' => (
|
||||
is => 'ro',
|
||||
isa => 'Maybe[ArrayRef]',
|
||||
requierd => 0,
|
||||
);
|
||||
|
||||
has 'links' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[HashRef]',
|
||||
|
Reference in New Issue
Block a user