3
0

modifications de dernière minute, mise en prod réussie \o/

This commit is contained in:
karchnu 2015-10-14 00:50:23 +02:00
parent 527313614c
commit e94224b6f2
4 changed files with 58 additions and 29 deletions

View File

@ -4,6 +4,7 @@ use Moo;
use db; use db;
use zone; use zone;
use configuration ':all';
has db => ( is => 'rw', builder => '_void'); has db => ( is => 'rw', builder => '_void');
@ -16,6 +17,9 @@ sub BUILD {
my ($self) = @_; my ($self) = @_;
$$self{db} = db->new(data => $self); $$self{db} = db->new(data => $self);
my $tmpdir = get_tmpdir_from_uri($$self{tmpdir});
-f $tmpdir || qx/mkdir -p $tmpdir/;
my $db = $$self{database}; my $db = $$self{database};
unless(exists $$db{sgbd} && exists $$db{name} unless(exists $$db{sgbd} && exists $$db{name}
&& exists $$db{host} && exists $$db{port} && exists $$db{host} && exists $$db{port}

View File

@ -16,6 +16,7 @@ get_v6_from_cfg
get_host_from_cfg get_host_from_cfg
get_user_from_cfg get_user_from_cfg
get_port_from_cfg get_port_from_cfg
get_tmpdir_from_uri
/; /;
# bundle of exports (tags) # bundle of exports (tags)
@ -30,6 +31,7 @@ get_v6_from_cfg
get_host_from_cfg get_host_from_cfg
get_user_from_cfg get_user_from_cfg
get_port_from_cfg get_port_from_cfg
get_tmpdir_from_uri
/] ); /] );
sub is_conf_file { sub is_conf_file {
@ -102,6 +104,14 @@ sub get_v4_from_cfg {
$$cfg{domain}{v4} // get_v4_from_name($$cfg{domain}{name}) $$cfg{domain}{v4} // get_v4_from_name($$cfg{domain}{name})
} }
sub get_tmpdir_from_uri {
my $tmpdir = shift;
unless($tmpdir) {
die 'There is no tmpdir';
}
URI->new($tmpdir)->path;
}
sub get_zonedir_from_cfg { sub get_zonedir_from_cfg {
my $cfg = shift; my $cfg = shift;
unless($$cfg{zonedir}) { unless($$cfg{zonedir}) {

View File

@ -9,16 +9,20 @@ has [ qw/mycfg tmpdir primarydnsserver secondarydnsserver/ ] => qw/is ro require
sub reload { sub reload {
my ($self, $domain) = @_; my ($self, $domain) = @_;
my $cmd = "rndc reload $domain "; my $cmd = "rndc reload $domain";
qx/$cmd/;
$cmd = "rndc notify $domain";
qx/$cmd/;
my $user = get_user_from_cfg($$self{mycfg}); #my $cmd = "rndc reload $domain ";
my $host = get_host_from_cfg($$self{mycfg}); #my $user = get_user_from_cfg($$self{mycfg});
my $port = get_port_from_cfg($$self{mycfg}); #my $host = get_host_from_cfg($$self{mycfg});
#my $port = get_port_from_cfg($$self{mycfg});
remotecmd $user, $host, $port, $cmd; #remotecmd $user, $host, $port, $cmd;
$cmd = "rndc notify $domain "; #$cmd = "rndc notify $domain ";
remotecmd $user, $host, $port, $cmd; #remotecmd $user, $host, $port, $cmd;
} }
sub primary_addzone { sub primary_addzone {
@ -44,11 +48,14 @@ sub primary_addzone {
$cmd .= " }; notify yes; };\""; $cmd .= " }; notify yes; };\"";
} }
my $user = get_user_from_cfg($$self{mycfg}); # if remote rndc
my $host = get_host_from_cfg($$self{mycfg}); #my $user = get_user_from_cfg($$self{mycfg});
my $port = get_port_from_cfg($$self{mycfg}); #my $host = get_host_from_cfg($$self{mycfg});
#my $port = get_port_from_cfg($$self{mycfg});
remotecmd $user, $host, $port, $cmd; #remotecmd $user, $host, $port, $cmd;
qx/$cmd/;
} }
sub reconfig { sub reconfig {
@ -56,17 +63,19 @@ sub reconfig {
my $cmd = "rndc reconfig "; my $cmd = "rndc reconfig ";
my $user = get_user_from_cfg($$self{mycfg}); #my $user = get_user_from_cfg($$self{mycfg});
my $host = get_host_from_cfg($$self{mycfg}); #my $host = get_host_from_cfg($$self{mycfg});
my $port = get_port_from_cfg($$self{mycfg}); #my $port = get_port_from_cfg($$self{mycfg});
remotecmd $user, $host, $port, $cmd; #remotecmd $user, $host, $port, $cmd;
qx/$cmd/;
} }
sub delzone { sub delzone {
my ($self, $domain) = @_; my ($self, $domain) = @_;
my $cmd = "rndc delzone $domain "; my $cmd = "sudo rndc delzone $domain ";
my $user = get_user_from_cfg($$self{mycfg}); my $user = get_user_from_cfg($$self{mycfg});
my $host = get_host_from_cfg($$self{mycfg}); my $host = get_host_from_cfg($$self{mycfg});

View File

@ -15,8 +15,7 @@ sub reload_sec {
$self->_reload_conf($slavedzones); $self->_reload_conf($slavedzones);
my $cmd = "sudo nsdc rebuild && " my $cmd = "sudo nsdc rebuild && sudo nsdc restart && sudo nsdc patch ";
. " sudo nsdc restart ";
my $user = get_user_from_cfg($$self{mycfg}); my $user = get_user_from_cfg($$self{mycfg});
my $host = get_host_from_cfg($$self{mycfg}); my $host = get_host_from_cfg($$self{mycfg});
@ -42,28 +41,36 @@ sub _reload_conf {
copycat $remote, $f; copycat $remote, $f;
my $data = read_file $f; my $data = read_file $f;
# if it's the first time we get the configuration, fresh start
$data .= "\n## BEGIN_GENERATED" if( $data !~ /BEGIN_GENERATED/);
my $v4 = get_v4_from_cfg($$self{primarydnsserver});
my $v6 = get_v6_from_cfg($$self{primarydnsserver});
my $debut = "## BEGIN_GENERATED"; my $debut = "## BEGIN_GENERATED";
my $nouveau = ''; my $nouveau = '';
my $dnsslavekey = get_dnsslavekey_from_cfg($$self{primarydnsserver}); my $dnsslavekey = get_dnsslavekey_from_cfg($$self{primarydnsserver});
for(@{$slavedzones}) { for(@{$slavedzones}) {
$nouveau .= "zone:\n\n\tname: \"$_\"\n" $nouveau .= "zone:\n\tname: \"$$_{domain}\"\n"
. "\tzonefile: \"slave/$_\"\n\n"; . "\tzonefile: \"slave/$$_{domain}\"\n";
my $v4 = get_v4_from_cfg($$self{primarydnsserver}); say "domain : $$_{domain}";
my $v6 = get_v6_from_cfg($$self{primarydnsserver});
if($v4) { if($v4) {
# allow notify & request xfr, v4 & v6 # allow notify & request xfr, v4 & v6
$nouveau .= "\tallow-notify: $v4 $dnsslavekey \n" $nouveau .= "\tallow-notify: $v4 \"$dnsslavekey\" \n"
. "\trequest-xfr: $v4 $dnsslavekey \n\n"; . "\trequest-xfr: $v4 \"$dnsslavekey\" \n";
} }
if($v6) { if($v6) {
$nouveau .= "\tallow-notify: $v6 $dnsslavekey \n" $nouveau .= "\tallow-notify: $v6 \"$dnsslavekey\" \n"
. "\trequest-xfr: $v6 $dnsslavekey \n\n"; . "\trequest-xfr: $v6 \"$dnsslavekey\" \n";
} }
$nouveau .= "\n";
} }
$data =~ s/$debut.*/$debut\n$nouveau/gsm; $data =~ s/$debut.*/$debut\n$nouveau/gsm;
@ -71,10 +78,9 @@ sub _reload_conf {
write_file $f, $data; write_file $f, $data;
copycat $f, $remote; copycat $f, $remote;
my $cmd = "sudo nsdc patch && " my $cmd = "sudo nsdc patch && sudo rm /var/nsd3/ixfr.db";
. " sudo rm /var/nsd3/ixfr.db";
remotecmd $user, $host, $port, $cmd; remotecmd $user, $host, $port, $cmd
} }
sub reconfig { sub reconfig {