diff --git a/scripts/dhcp b/scripts/dhcp index 19f8cdb..3370e68 100755 --- a/scripts/dhcp +++ b/scripts/dhcp @@ -27,6 +27,17 @@ class DhcpRegistry < Registry end dhcp_path = Pathname.new(File.expand_path("../../dhcp.peers.conf", __FILE__)) File.open(dhcp_path, "w+").write(dhcp_template.render(leases: static_leases)) + + reload_dhcp + end + + def reload_dhcp + command = try(data, "host", "reload_command") + if command.nil? + puts "skip to reload dhcpd because reload_command is not defined" + else + sh(command) + end end end diff --git a/scripts/openvpn b/scripts/openvpn index eefca66..08473c6 100755 --- a/scripts/openvpn +++ b/scripts/openvpn @@ -113,9 +113,8 @@ class OpenvpnRegistry < Registry end def service_command(command_type, peer_name) - openvpn = @host["openvpn"] || {} cmd_name = "#{command_type}_command" - command = openvpn[cmd_name] + command = try(@host, "openvpn", cmd_name) if command.nil? puts "skip to #{command_type} openvpn because #{cmd_name} is not defined" else diff --git a/scripts/utils.rb b/scripts/utils.rb index d410700..dac4bcd 100644 --- a/scripts/utils.rb +++ b/scripts/utils.rb @@ -41,6 +41,18 @@ def die(msg) exit(1) end +def try(hash, *args) + result = hash + args.each do |arg| + if result.respond_to?(:[]) && result[arg] + result = result[arg] + else + return nil + end + end + result +end + class TemplateContext < OpenStruct def get_binding binding