mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Handle run-once services. Stub implementation of --stop.
This commit is contained in:
49
bin/pt-agent
49
bin/pt-agent
@@ -1354,7 +1354,7 @@ has 'tasks' => (
|
|||||||
has 'run_schedule' => (
|
has 'run_schedule' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Str',
|
isa => 'Str',
|
||||||
required => 1,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'spool_schedule' => (
|
has 'spool_schedule' => (
|
||||||
@@ -1363,7 +1363,7 @@ has 'spool_schedule' => (
|
|||||||
required => 0,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'run_once_on_start' => (
|
has 'run_once' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Bool',
|
isa => 'Bool',
|
||||||
required => 0,
|
required => 0,
|
||||||
@@ -4105,6 +4105,7 @@ sub new {
|
|||||||
daemonize => $args{daemonize},
|
daemonize => $args{daemonize},
|
||||||
force_log_file => $args{force_log_file},
|
force_log_file => $args{force_log_file},
|
||||||
parent_exit => $args{parent_exit},
|
parent_exit => $args{parent_exit},
|
||||||
|
pid_file_owner => 0,
|
||||||
};
|
};
|
||||||
return bless $self, $class;
|
return bless $self, $class;
|
||||||
}
|
}
|
||||||
@@ -4309,7 +4310,7 @@ sub remove_pid_file {
|
|||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
if ( ($self->{pid_file_owner} || 0) == $PID ) {
|
if ( $self->{pid_file_owner} == $PID ) {
|
||||||
$self->remove_pid_file();
|
$self->remove_pid_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4839,6 +4840,13 @@ sub main {
|
|||||||
DSNParser => $dp,
|
DSNParser => $dp,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# ########################################################################
|
||||||
|
# --stop
|
||||||
|
# ########################################################################
|
||||||
|
if ( my $stop = $o->get('stop') ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
# --run-service
|
# --run-service
|
||||||
# This runs locally and offline, doesn't need a web API connection.
|
# This runs locally and offline, doesn't need a web API connection.
|
||||||
@@ -5390,16 +5398,17 @@ sub get_services {
|
|||||||
json => $args{json}, # optional, for testing
|
json => $args{json}, # optional, for testing
|
||||||
);
|
);
|
||||||
|
|
||||||
schedule_services(
|
# TODO: this probably can't/won't fail, but if it does, is it
|
||||||
|
# worth setting success=0?
|
||||||
|
start_services(
|
||||||
services => $new_services,
|
services => $new_services,
|
||||||
lib_dir => $lib_dir,
|
lib_dir => $lib_dir,
|
||||||
bin_dir => $args{bin_dir}, # optional, for testing
|
bin_dir => $args{bin_dir}, # optional, for testing
|
||||||
);
|
);
|
||||||
|
|
||||||
# TODO: this probably can't/won't fail, but if it does, is it
|
schedule_services(
|
||||||
# worth setting success=0?
|
|
||||||
start_services(
|
|
||||||
services => $new_services,
|
services => $new_services,
|
||||||
|
lib_dir => $lib_dir,
|
||||||
bin_dir => $args{bin_dir}, # optional, for testing
|
bin_dir => $args{bin_dir}, # optional, for testing
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -5672,7 +5681,14 @@ sub schedule_services {
|
|||||||
|
|
||||||
_info("Scheduling services");
|
_info("Scheduling services");
|
||||||
|
|
||||||
my $new_crontab = make_new_crontab(%args);
|
# Only schedule "periodic" services, i.e. ones that run periodically,
|
||||||
|
# not just once.
|
||||||
|
my @periodic_services = grep { !$_->run_once; } @$services;
|
||||||
|
|
||||||
|
my $new_crontab = make_new_crontab(
|
||||||
|
%args,
|
||||||
|
services => \@periodic_services,
|
||||||
|
);
|
||||||
_info("New crontab:\n" . $new_crontab || '');
|
_info("New crontab:\n" . $new_crontab || '');
|
||||||
|
|
||||||
my $crontab_file = "$lib_dir/crontab";
|
my $crontab_file = "$lib_dir/crontab";
|
||||||
@@ -5742,20 +5758,23 @@ sub start_services {
|
|||||||
my (%args) = @_;
|
my (%args) = @_;
|
||||||
have_required_args(\%args, qw(
|
have_required_args(\%args, qw(
|
||||||
services
|
services
|
||||||
|
lib_dir
|
||||||
)) or die;
|
)) or die;
|
||||||
my $services = $args{services};
|
my $services = $args{services};
|
||||||
|
my $lib_dir = $args{lib_dir};
|
||||||
|
|
||||||
# Optional args
|
# Optional args
|
||||||
my $bin_dir = defined $args{bin_dir} ? $args{bin_dir}
|
my $bin_dir = defined $args{bin_dir} ? $args{bin_dir}
|
||||||
: "$FindBin::Bin/";
|
: "$FindBin::Bin/";
|
||||||
|
|
||||||
foreach my $service ( @$services ) {
|
foreach my $service ( @$services ) {
|
||||||
next unless $service->run_once_on_start;
|
next unless $service->run_once;
|
||||||
my $cmd = "${bin_dir}pt-agent --run-service " . $service->name;
|
my $cmd = "${bin_dir}pt-agent --run-service " . $service->name
|
||||||
|
. " </dev/null"
|
||||||
|
. " >$lib_dir/logs/" . $service->name . ".log"
|
||||||
|
. " 2>&1 &";
|
||||||
_info('Starting ' . $service->name . ' service: ' . $cmd);
|
_info('Starting ' . $service->name . ' service: ' . $cmd);
|
||||||
# TODO: need service-specific log files, else where is this output
|
system($cmd);
|
||||||
# supposed to go?
|
|
||||||
system("$cmd </dev/null >/dev/null 2>&1 &");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -6746,6 +6765,10 @@ reads data from this directory. Each service has its own subdirectory,
|
|||||||
like C<--spool/query-history> for the Query History service. Data
|
like C<--spool/query-history> for the Query History service. Data
|
||||||
is removed by L<"--send-data"> after it is successfully sent to Percona.
|
is removed by L<"--send-data"> after it is successfully sent to Percona.
|
||||||
|
|
||||||
|
=item --stop
|
||||||
|
|
||||||
|
Stop pt-agent and all services.
|
||||||
|
|
||||||
=item --user
|
=item --user
|
||||||
|
|
||||||
short form: -u; type: string
|
short form: -u; type: string
|
||||||
|
@@ -37,7 +37,7 @@ has 'tasks' => (
|
|||||||
has 'run_schedule' => (
|
has 'run_schedule' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Str',
|
isa => 'Str',
|
||||||
required => 1,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'spool_schedule' => (
|
has 'spool_schedule' => (
|
||||||
@@ -46,7 +46,7 @@ has 'spool_schedule' => (
|
|||||||
required => 0,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'run_once_on_start' => (
|
has 'run_once' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Bool',
|
isa => 'Bool',
|
||||||
required => 0,
|
required => 0,
|
||||||
|
Reference in New Issue
Block a user