Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* New Feature: Supporting "ssh_options"

  • Loading branch information...
commit fe6b425bf323e577a065b963151aa7d4c14bd856 1 parent cc126a5
@yoshinorim authored
View
10 bin/masterha_secondary_check
@@ -26,10 +26,8 @@ use Pod::Usage;
use MHA::ManagerConst;
my @monitoring_servers;
-my (
- $help, $version, $ssh_user, $ssh_port,
- $master_host, $master_ip, $master_port
-);
+my ( $help, $version, $ssh_user, $ssh_port, $ssh_options, $master_host,
+ $master_ip, $master_port );
$| = 1;
GetOptions(
@@ -38,6 +36,7 @@ GetOptions(
'secondary_host=s' => \@monitoring_servers,
'user=s' => \$ssh_user,
'port=s' => \$ssh_port,
+ 'options=s' => \$ssh_options,
'master_host=s' => \$master_host,
'master_ip=s' => \$master_ip,
'master_port=i' => \$master_port,
@@ -59,6 +58,9 @@ unless ($master_host) {
$ssh_user = "root" unless ($ssh_user);
$ssh_port = 22 unless ($ssh_port);
$master_port = 3306 unless ($master_port);
+if ($ssh_options) {
+ $MHA::ManagerConst::SSH_OPT_CHECK = $ssh_options;
+}
sub exit_by_signal {
exit 1;
View
16 lib/MHA/Config.pm
@@ -31,7 +31,7 @@ use MHA::NodeUtil;
use MHA::ManagerConst;
my @PARAM_ARRAY =
- qw/ hostname ip port ssh_host ssh_ip ssh_port node_label candidate_master no_master ignore_fail skip_init_ssh_check skip_reset_slave user password repl_user repl_password disable_log_bin master_pid_file handle_raw_binlog ssh_user remote_workdir master_binlog_dir log_level manager_workdir manager_log check_repl_delay check_repl_filter latest_priority multi_tier_slave ping_interval ping_type secondary_check_script master_ip_failover_script master_ip_online_change_script shutdown_script report_script init_conf_load_script /;
+ qw/ hostname ip port ssh_host ssh_ip ssh_port ssh_options node_label candidate_master no_master ignore_fail skip_init_ssh_check skip_reset_slave user password repl_user repl_password disable_log_bin master_pid_file handle_raw_binlog ssh_user remote_workdir master_binlog_dir log_level manager_workdir manager_log check_repl_delay check_repl_filter latest_priority multi_tier_slave ping_interval ping_type secondary_check_script master_ip_failover_script master_ip_online_change_script shutdown_script report_script init_conf_load_script /;
my %PARAM;
for (@PARAM_ARRAY) { $PARAM{$_} = 1; }
@@ -89,6 +89,20 @@ sub parse_server {
$value{ssh_port} = 22 unless ( $value{ssh_port} );
}
+ $value{ssh_options} = $param_arg->{ssh_options};
+ if ( $value{ssh_options} ) {
+ $value{ssh_options} =~ s/['"]//g;
+ if ( $value{ssh_options} ) {
+ $MHA::ManagerConst::USE_SSH_OPTIONS = 1;
+ $MHA::ManagerConst::SSH_OPT_ALIVE =
+ $MHA::ManagerConst::SSH_OPT_ALIVE_DEFAULT . " $value{ssh_options}";
+ $MHA::NodeConst::SSH_OPT_ALIVE =
+ $MHA::ManagerConst::SSH_OPT_ALIVE_DEFAULT . " $value{ssh_options}";
+ $MHA::ManagerConst::SSH_OPT_CHECK =
+ $MHA::ManagerConst::SSH_OPT_CHECK_DEFAULT . " $value{ssh_options}";
+ }
+ }
+
$value{user} = $param_arg->{user};
if ( !defined( $value{user} ) ) {
$value{user} = $default->{user};
View
3  lib/MHA/HealthCheck.pm
@@ -322,6 +322,9 @@ sub secondary_check($) {
. " --master_host=$self->{hostname} "
. " --master_ip=$self->{ip} "
. " --master_port=$self->{port}";
+ if ($MHA::ManagerConst::USE_SSH_OPTIONS) {
+ $command .= " --options='$MHA::ManagerConst::SSH_OPT_CHECK' ";
+ }
$log->info("Executing seconary network check script: $command");
my ( $high, $low ) =
MHA::ManagerUtil::exec_system( $command, $self->{logfile} );
View
5 lib/MHA/ManagerConst.pm
@@ -72,9 +72,12 @@ our $ST_TIMESTAMP_OLD_S = "$ST_TIMESTAMP_OLD:TIMESTAMP_OLD";
our $ST_FAILOVER_RUNNING_S = "$ST_FAILOVER_RUNNING:FAILOVER_RUNNING";
our $ST_FAILOVER_ERROR_S = "$ST_FAILOVER_ERROR:FAILOVER_ERROR";
-our $SSH_OPT_ALIVE = $MHA::NodeConst::SSH_OPT_ALIVE;
+our $USE_SSH_OPTIONS = 0;
+our $SSH_OPT_ALIVE = $MHA::NodeConst::SSH_OPT_ALIVE;
our $SSH_OPT_CHECK =
"-o StrictHostKeyChecking=no -o ConnectTimeout=4 -o PasswordAuthentication=no";
+our $SSH_OPT_ALIVE_DEFAULT = $SSH_OPT_ALIVE;
+our $SSH_OPT_CHECK_DEFAULT = $SSH_OPT_CHECK;
our $PING_TYPE_CONNECT = "CONNECT";
our $PING_TYPE_SELECT = "SELECT";
View
10 lib/MHA/ManagerUtil.pm
@@ -76,8 +76,9 @@ sub exec_ssh_check_cmd($$$$) {
my $log_output = shift;
my $ret;
return exec_system(
- "ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $ssh_port $ssh_host $ssh_cmd",
- $log_output );
+ "ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $ssh_port $ssh_host \"$ssh_cmd\"",
+ $log_output
+ );
}
sub exec_ssh_cmd($$$$) {
@@ -87,8 +88,9 @@ sub exec_ssh_cmd($$$$) {
my $log_output = shift;
my $ret;
return exec_system(
- "ssh $MHA::ManagerConst::SSH_OPT_ALIVE -p $ssh_port $ssh_host $ssh_cmd",
- $log_output );
+ "ssh $MHA::ManagerConst::SSH_OPT_ALIVE -p $ssh_port $ssh_host \"$ssh_cmd\"",
+ $log_output
+ );
}
sub check_node_version {
View
20 lib/MHA/MasterFailover.pm
@@ -321,7 +321,8 @@ sub force_shutdown_internal($) {
else {
$command .= " --command=stop";
}
- $command .= $dead_master->get_ssh_args_if("orig");
+ $command .=
+ $dead_master->get_ssh_args_if( 1, "orig", $_real_ssh_reachable );
$log->info("Executing master IP deactivatation script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -363,7 +364,8 @@ sub force_shutdown_internal($) {
" --host=$dead_master->{hostname} --ip=$dead_master->{ip} --port=$dead_master->{port} ";
$command .= " --pid_file=$dead_master->{master_pid_file}"
if ( $dead_master->{master_pid_file} );
- $command .= $dead_master->get_ssh_args_if("shutdown");
+ $command .=
+ $dead_master->get_ssh_args_if( 1, "shutdown", $_real_ssh_reachable );
$log->info("Executing SHUTDOWN script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -626,6 +628,9 @@ sub find_slave_with_all_relay_logs {
$log->info(
"Checking whether $latest_slave->{hostname} has relay logs from the oldest position.."
);
+ if ($MHA::ManagerConst::USE_SSH_OPTIONS) {
+ $command .= " --ssh_options='$MHA::NodeConst::SSH_OPT_ALIVE' ";
+ }
$log->info("Executing command: $command :");
my ( $high, $low ) =
MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $latest_slave->{ssh_port},
@@ -846,6 +851,9 @@ sub generate_diff_from_readpos {
if ( $target->{log_level} eq "debug" ) {
$command .= " --debug ";
}
+ if ($MHA::ManagerConst::USE_SSH_OPTIONS) {
+ $command .= " --ssh_options='$MHA::NodeConst::SSH_OPT_ALIVE' ";
+ }
$logger->info("Executing command: $command");
return exec_ssh_child_cmd( $ssh_user_host, $target->{ssh_port}, $command,
$logger, "$g_workdir/$target->{hostname}_$target->{port}.work" );
@@ -1114,6 +1122,9 @@ sub apply_diff {
if ( $target->{log_level} eq "debug" ) {
$command .= " --debug ";
}
+ if ($MHA::ManagerConst::USE_SSH_OPTIONS) {
+ $command .= " --ssh_options='$MHA::NodeConst::SSH_OPT_ALIVE' ";
+ }
$logger->info("Executing command: $command --slave_pass=xxx");
if ( $target->{password} ne "" ) {
$command .= " --slave_pass=$target->{password} ";
@@ -1214,8 +1225,9 @@ sub recover_master($$$) {
if ( $new_master->{master_ip_failover_script} ) {
my $command =
"$new_master->{master_ip_failover_script} --command=start --ssh_user=$new_master->{ssh_user} --orig_master_host=$dead_master->{hostname} --orig_master_ip=$dead_master->{ip} --orig_master_port=$dead_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
- $command .= $dead_master->get_ssh_args_if("orig");
- $command .= $new_master->get_ssh_args_if("new");
+ $command .=
+ $dead_master->get_ssh_args_if( 1, "orig", $_real_ssh_reachable );
+ $command .= $new_master->get_ssh_args_if( 2, "new", 1 );
$log->info("Executing master IP activate script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
View
9 lib/MHA/MasterMonitor.pm
@@ -119,6 +119,9 @@ sub check_slave_env() {
if ( $s->{log_level} eq "debug" ) {
$command .= " --debug ";
}
+ if ($MHA::ManagerConst::USE_SSH_OPTIONS) {
+ $command .= " --ssh_options='$MHA::NodeConst::SSH_OPT_ALIVE' ";
+ }
$log->info(" Executing command : $command --slave_pass=xxx");
if ( $s->{password} ne "" ) {
@@ -143,7 +146,7 @@ sub check_scripts($) {
if ( $current_master->{master_ip_failover_script} ) {
my $command =
"$current_master->{master_ip_failover_script} --command=status --ssh_user=$current_master->{ssh_user} --orig_master_host=$current_master->{hostname} --orig_master_ip=$current_master->{ip} --orig_master_port=$current_master->{port}";
- $command .= $current_master->get_ssh_args_if("orig");
+ $command .= $current_master->get_ssh_args_if( 1, "orig", 1 );
$log->info("Checking master_ip_failover_script status:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -163,8 +166,8 @@ sub check_scripts($) {
if ( $current_master->{shutdown_script} ) {
my $command =
-"$current_master->{shutdown_script} --command=status --host=$current_master->{hostname} --ip=$current_master->{ip}";
- $command .= $current_master->get_ssh_args_if("shutdown");
+"$current_master->{shutdown_script} --command=status --ssh_user=$current_master->{ssh_user} --host=$current_master->{hostname} --ip=$current_master->{ip}";
+ $command .= $current_master->get_ssh_args_if( 1, "shutdown", 1 );
$log->info("Checking shutdown script status:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
View
8 lib/MHA/MasterRotate.pm
@@ -283,8 +283,8 @@ sub reject_update($$) {
if ( $new_master->{master_ip_online_change_script} ) {
my $command =
"$orig_master->{master_ip_online_change_script} --command=stop --orig_master_host=$orig_master->{hostname} --orig_master_ip=$orig_master->{ip} --orig_master_port=$orig_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
- $command .= $orig_master->get_ssh_args_if("orig");
- $command .= $new_master->get_ssh_args_if("new");
+ $command .= $orig_master->get_ssh_args_if( 1, "orig", 1 );
+ $command .= $new_master->get_ssh_args_if( 2, "new", 1 );
$log->info(
"Executing master ip online change script to disable write on the current master:"
);
@@ -392,8 +392,8 @@ sub switch_master($$$$) {
if ( $new_master->{master_ip_online_change_script} ) {
my $command =
"$new_master->{master_ip_online_change_script} --command=start --orig_master_host=$orig_master->{hostname} --orig_master_ip=$orig_master->{ip} --orig_master_port=$orig_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
- $command .= $orig_master->get_ssh_args_if("orig");
- $command .= $new_master->get_ssh_args_if("new");
+ $command .= $orig_master->get_ssh_args_if( 1, "orig", 1 );
+ $command .= $new_master->get_ssh_args_if( 2, "new", 1 );
$log->info(
"Executing master ip online change script to allow write on the new master:"
);
View
15 lib/MHA/Server.pm
@@ -1049,8 +1049,10 @@ sub print_filter {
}
sub get_ssh_args_if {
- my $self = shift;
- my $type = shift;
+ my $self = shift;
+ my $arg_number = shift;
+ my $type = shift;
+ my $ssh_reachable = shift;
my $arg = " ";
my $head = "";
@@ -1075,6 +1077,15 @@ sub get_ssh_args_if {
if ( $self->{ssh_port} ne 22 ) {
$arg .= $head . "ssh_port=$self->{ssh_port}";
}
+
+ if ( $MHA::ManagerConst::USE_SSH_OPTIONS && $arg_number <= 1 ) {
+ if ($ssh_reachable) {
+ $arg .= " --ssh_options='$MHA::NodeConst::SSH_OPT_ALIVE' ";
+ }
+ else {
+ $arg .= " --ssh_options='$MHA::ManagerConst::SSH_OPT_CHECK' ";
+ }
+ }
return $arg;
}
Please sign in to comment.
Something went wrong with that request. Please try again.