diff --git a/debian/control b/debian/control index b7ddde62..a98d2de4 100644 --- a/debian/control +++ b/debian/control @@ -14,6 +14,7 @@ Build-Depends: asciidoc, liblist-moreutils-perl, libnet-netmask-perl, libregexp-ipv6-perl, + libsocket-perl, libsys-hostname-long-perl, libtemplate-perl, libyaml-perl, @@ -36,6 +37,7 @@ Depends: etckeeper, liblist-moreutils-perl, libnet-netmask-perl, libregexp-ipv6-perl, + libsocket-perl, libsys-hostname-long-perl, libtemplate-perl, libyaml-perl, diff --git a/sbin/ngcp-sync-constants b/sbin/ngcp-sync-constants index f2ab2a8c..f6641d38 100755 --- a/sbin/ngcp-sync-constants +++ b/sbin/ngcp-sync-constants @@ -8,6 +8,9 @@ use YAML::Tiny; use Getopt::Long; use Sys::Hostname; use Data::Dumper; +use Socket; +use List::MoreUtils qw(any); +use Data::Validate::IP qw(is_ipv4 is_ipv6); use IPC::System::Simple qw(system capturex); #---------------------------------------------------------------------- use constant CONSTANTS_YML => "/etc/ngcp-config/constants.yml"; @@ -209,6 +212,12 @@ sub sync_repuser { my $minfo = "/var/lib/mysql$dbid/master.info"; my $mhost = $args{mhost}; my $mport = $args{mport} || 3306; + my $mhost_ip = $args{mhost}; + + unless ( is_ipv4($mhost) or is_ipv6($mhost) ) { + $mhost_ip = inet_ntoa(scalar(gethostbyname($mhost))); + print " --> $mhost => $mhost_ip\n" if $debug; + } print " --> syncing replication user '$user' for master host '$mhost'\n" if $debug; if(-f $minfo) { @@ -220,12 +229,12 @@ sub sync_repuser { } my @minfo_content = <$mfh>; close $mfh; - unless(grep {/^${mhost}\s*$/}@minfo_content) { - print STDERR "${mhost} not found at $minfo. Fix replication manually"; + unless(any {/^(${mhost}|${mhost_ip})\s*$/} @minfo_content) { + print STDERR "${mhost} or ${mhost_ip} were not found at $minfo. Fix replication manually"; $error = 2; return; } - unless(grep {/^${pass}\s*$/} @minfo_content) { + unless(any {/^${pass}\s*$/} @minfo_content) { set_master_pass( dbh => $dbh, user => $user, pass => $pass