lxc-config/hooks/update-zone

38 lines
1.1 KiB
Plaintext
Raw Normal View History

2014-08-18 08:29:43 +00:00
#!/usr/bin/env ruby
2015-01-30 08:08:18 +00:00
require "json"
require "pathname"
require_relative "lib/lxc"
2014-08-18 08:29:43 +00:00
DNS_CONTAINER = "dns"
2015-01-30 08:08:18 +00:00
def main
registry = Lxc::Registry.new
registry.data["zone"] ||= {}
registry.data["zone"]["serial"] += 1
registry.save
root_path = Lxc::CONFIG_ROOT
2015-12-13 19:24:00 +00:00
if subnet = registry.data["zone"]["ula_subnet"]
Lxc::RdnsZone.new(registry.data, "ula", subnet).write_zone_file(root_path)
2014-08-18 08:29:43 +00:00
end
2015-12-13 19:24:00 +00:00
if subnet = registry.data["zone"]["v4_subnet"]
Lxc::RdnsZone.new(registry.data, "ipv4", subnet).write_zone_file(root_path)
2014-08-18 08:29:43 +00:00
end
2015-12-13 19:24:00 +00:00
if subnet = registry.data["zone"]["v6_subnet"]
Lxc::RdnsZone.new(registry.data, "ipv6", subnet).write_zone_file(root_path)
2015-11-29 18:30:38 +00:00
end
2015-01-30 08:08:18 +00:00
root_path = Pathname.new(File.expand_path("../..", __FILE__))
2015-08-11 21:32:26 +00:00
zone_template = Lxc::Template.new(root_path.join("hooks/templates/lxc-zone.erb"))
2015-01-30 08:08:18 +00:00
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)
2014-08-18 08:29:43 +00:00
2015-01-30 08:08:18 +00:00
Lxc::Utils.sh("lxc-attach", "-n", DNS_CONTAINER, "--", "rndc", "reload")
2015-01-03 16:57:39 +00:00
end
2014-08-18 08:29:43 +00:00
2015-01-03 16:57:39 +00:00
main