lxc-config/hooks/update-zone

33 lines
940 B
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"]["v4_subnet"]
Lxc::RdnsZone.new(registry.data, subnet).write_zone_file(root_path)
end
if subnet = registry.data["zone"]["v6_subnet"]
Lxc::RdnsZone.new(registry.data, subnet).write_zone_file(root_path)
end
root_path = Pathname.new(File.expand_path("../..", __FILE__))
zone_template = Lxc::Template.new(root_path.join("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