lxc-config/hooks/update-zone

38 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require "json"
require "pathname"
require_relative "lib/lxc"
DNS_CONTAINER = "dns"
def main
registry = Lxc::Registry.new
registry.data["zone"] ||= {}
registry.data["zone"]["serial"] += 1
registry.save
root_path = Lxc::CONFIG_ROOT
if subnet = registry.data["zone"]["ula_subnet"]
Lxc::RdnsZone.new(registry.data, "ula", subnet).write_zone_file(root_path)
end
if subnet = registry.data["zone"]["v4_subnet"]
Lxc::RdnsZone.new(registry.data, "ipv4", subnet).write_zone_file(root_path)
end
if subnet = registry.data["zone"]["v6_subnet"]
Lxc::RdnsZone.new(registry.data, "ipv6", subnet).write_zone_file(root_path)
end
root_path = Pathname.new(File.expand_path("../..", __FILE__))
zone_template = Lxc::Template.new(root_path.join("hooks/templates/lxc-zone.erb"))
zone = registry.data["zone"] || {}
zone_name = registry.data["zone"]["domain"] || "lxc"
zone_template.write(root_path.join("zones", "#{zone_name}.zone"), data: registry.data, zone: zone)
Lxc::Utils.sh("lxc-attach", "-n", DNS_CONTAINER, "--", "rndc", "reload")
end
main