Powerdns-sync: wait for a few minutes before updating the zone.
This commit is contained in:
parent
0eca58ffa8
commit
b633dbe740
@ -8,7 +8,7 @@ class Context
|
|||||||
class_property powerdns_dir : String = ""
|
class_property powerdns_dir : String = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_file(domain : String) : Nil
|
def copy_domain_files(domain : String) : Nil
|
||||||
src = "#{Context.dnsmanagerd_dir}/#{domain}"
|
src = "#{Context.dnsmanagerd_dir}/#{domain}"
|
||||||
dest = "#{Context.powerdns_dir}/#{domain}"
|
dest = "#{Context.powerdns_dir}/#{domain}"
|
||||||
puts "copying #{src} -> #{dest}"
|
puts "copying #{src} -> #{dest}"
|
||||||
@ -18,47 +18,38 @@ rescue e : File::AccessDeniedError
|
|||||||
puts "You don't have enough rights: #{e}"
|
puts "You don't have enough rights: #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def pdns_reload(domain : String) : Nil
|
def run_process(cmd : String, params : Array(String), env : Hash(String, String)) : Nil
|
||||||
puts "reloading a domain: pdns_control bind-reload-now #{domain}"
|
unless Process.run(cmd, params, env,
|
||||||
unless Process.run("pdns_control",
|
|
||||||
# PARAMETERS
|
|
||||||
[ "bind-reload-now", domain ],
|
|
||||||
# ENV
|
|
||||||
{ "HOME" => "/" },
|
|
||||||
true # clear environment
|
true # clear environment
|
||||||
# input: Process::Redirect::Inherit,
|
# input: Process::Redirect::Inherit,
|
||||||
# output: Process::Redirect::Inherit,
|
# output: Process::Redirect::Inherit,
|
||||||
# error: Process::Redirect::Inherit
|
# error: Process::Redirect::Inherit
|
||||||
).success?
|
).success?
|
||||||
puts "cannot run pdns_control bind-reload-now #{domain}"
|
puts "cannot run #{cmd} #{params.join(' ')}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pdns_reload(domain : String) : Nil
|
||||||
|
puts "reloading a domain: pdns_control bind-reload-now #{domain}"
|
||||||
|
run_process("pdns_control", [ "bind-reload-now", domain ], { "HOME" => "/" })
|
||||||
|
end
|
||||||
|
|
||||||
def update_domain(domain : String) : Nil
|
def update_domain(domain : String) : Nil
|
||||||
puts "domain to reload: #{domain}"
|
puts "domain to reload: #{domain}"
|
||||||
copy_file domain
|
copy_domain_files domain
|
||||||
pdns_reload domain
|
pdns_reload domain
|
||||||
end
|
end
|
||||||
|
|
||||||
def pdns_add(domain : String) : Nil
|
def pdns_add(domain : String) : Nil
|
||||||
puts "adding a new domain: pdns_control bind-add-zone #{Context.powerdns_dir}/#{domain}"
|
puts "adding a new domain: pdns_control bind-add-zone #{Context.powerdns_dir}/#{domain}"
|
||||||
unless Process.run("pdns_control",
|
run_process("pdns_control",
|
||||||
# PARAMETERS
|
|
||||||
[ "bind-add-zone", domain, "#{Context.powerdns_dir}/#{domain}" ],
|
[ "bind-add-zone", domain, "#{Context.powerdns_dir}/#{domain}" ],
|
||||||
# ENV
|
{ "HOME" => "/" })
|
||||||
{ "HOME" => "/" },
|
|
||||||
true # clear environment
|
|
||||||
# input: Process::Redirect::Inherit,
|
|
||||||
# output: Process::Redirect::Inherit,
|
|
||||||
# error: Process::Redirect::Inherit
|
|
||||||
).success?
|
|
||||||
puts "cannot run pdns_control bind-add-zone #{Context.powerdns_dir}/#{domain}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_domain(domain : String) : Nil
|
def add_domain(domain : String) : Nil
|
||||||
puts "domain to add: #{domain}"
|
puts "domain to add: #{domain}"
|
||||||
copy_file domain
|
copy_domain_files domain
|
||||||
pdns_add domain
|
pdns_add domain
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -80,25 +71,6 @@ Context.powerdns_dir = ARGV[1]
|
|||||||
dnsmanagerd_dir_content = Dir.children(Context.dnsmanagerd_dir).select { |d| ! d.ends_with? ".wip" }
|
dnsmanagerd_dir_content = Dir.children(Context.dnsmanagerd_dir).select { |d| ! d.ends_with? ".wip" }
|
||||||
powerdns_dir_content = Dir.children(Context.powerdns_dir)
|
powerdns_dir_content = Dir.children(Context.powerdns_dir)
|
||||||
|
|
||||||
if dnsmanagerd_dir_content.size < 1
|
|
||||||
puts "There is no entries in the dnsmanagerd bind9 directory"
|
|
||||||
puts "Assuming a configuration error"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if powerdns_dir_content.size < 1
|
|
||||||
puts "There is no entries in the powerdns bind9 directory"
|
|
||||||
puts "Assuming a configuration error"
|
|
||||||
exit 2
|
|
||||||
end
|
|
||||||
|
|
||||||
#dnsmanagerd_dir_content.each do |d|
|
|
||||||
# puts "dnsmanagerd_dir_content: #{d}"
|
|
||||||
#end
|
|
||||||
#powerdns_dir_content.each do |d|
|
|
||||||
# puts "powerdns_dir_content: #{d}"
|
|
||||||
#end
|
|
||||||
|
|
||||||
both = dnsmanagerd_dir_content & powerdns_dir_content
|
both = dnsmanagerd_dir_content & powerdns_dir_content
|
||||||
both.each do |d|
|
both.each do |d|
|
||||||
i1 = File.info "#{Context.dnsmanagerd_dir}/#{d}"
|
i1 = File.info "#{Context.dnsmanagerd_dir}/#{d}"
|
||||||
@ -106,18 +78,20 @@ both.each do |d|
|
|||||||
|
|
||||||
if i1.modification_time > i2.modification_time
|
if i1.modification_time > i2.modification_time
|
||||||
puts "has been modified: #{d}"
|
puts "has been modified: #{d}"
|
||||||
update_domain d
|
# Wait for a few minutes before changing anything, to avoid useless reloads.
|
||||||
|
if Time.local > i1.modification_time.shift minutes: 5
|
||||||
|
puts "file was modified more than 5 minutes ago"
|
||||||
|
update_domain d
|
||||||
|
else
|
||||||
|
puts "file has been modified less than 5 minutes ago: do not update yet"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "hasn't been modified: #{d}"
|
puts "hasn't been modified: #{d}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_add = dnsmanagerd_dir_content - powerdns_dir_content
|
to_add = dnsmanagerd_dir_content - powerdns_dir_content
|
||||||
to_add.each do |d|
|
to_add.each { |d| add_domain d }
|
||||||
add_domain d
|
|
||||||
end
|
|
||||||
|
|
||||||
to_delete = powerdns_dir_content - dnsmanagerd_dir_content
|
to_delete = powerdns_dir_content - dnsmanagerd_dir_content
|
||||||
to_delete.each do |d|
|
to_delete.each { |d| del_domain d }
|
||||||
del_domain d
|
|
||||||
end
|
|
||||||
|
Loading…
Reference in New Issue
Block a user