summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/services/vyos-hostsd14
-rwxr-xr-xsrc/system/on-dhcp-event.sh12
2 files changed, 14 insertions, 12 deletions
diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd
index 6017cea82..bf5d67cfa 100755
--- a/src/services/vyos-hostsd
+++ b/src/services/vyos-hostsd
@@ -28,6 +28,7 @@ import zmq
import collections
import jinja2
+from vyos.util import popen, process_named_running
debug = True
@@ -212,13 +213,17 @@ def handle_message(msg_json):
op = get_option(msg, 'op')
_type = get_option(msg, 'type')
+ changes = 0
+
if op == 'delete':
tag = get_option(msg, 'tag')
if _type == 'name_servers':
delete_name_servers(STATE, tag)
+ changes += 1
elif _type == 'hosts':
delete_hosts(STATE, tag)
+ changes += 1
else:
raise ValueError("Unknown message type {0}".format(_type))
elif op == 'add':
@@ -226,8 +231,10 @@ def handle_message(msg_json):
entries = get_option(msg, 'data')
if _type == 'name_servers':
add_name_servers(STATE, entries, tag)
+ changes += 1
elif _type == 'hosts':
add_hosts(STATE, entries, tag)
+ changes += 1
else:
raise ValueError("Unknown message type {0}".format(_type))
elif op == 'set':
@@ -236,6 +243,7 @@ def handle_message(msg_json):
data = get_option(msg, 'data')
if _type == 'host_name':
set_host_name(STATE, data)
+ changes += 1
else:
raise ValueError("Unknown message type {0}".format(_type))
elif op == 'get':
@@ -255,6 +263,12 @@ def handle_message(msg_json):
with open(STATE_FILE, 'w') as f:
json.dump(STATE, f)
+ if changes > 0:
+ if process_named_running("pdns_recursor"):
+ (ret,return_code) = popen("sudo rec_control --socket-dir=/run/powerdns reload-zones")
+ if return_code > 0:
+ logger.exception("PowerDNS rec_control failed to reload")
+
def exit_handler(sig, frame):
""" Clean up the state when shutdown correctly """
logger.info("Cleaning up state")
diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh
index 385ae460f..57f492401 100755
--- a/src/system/on-dhcp-event.sh
+++ b/src/system/on-dhcp-event.sh
@@ -20,7 +20,6 @@ client_ip=$3
client_mac=$4
domain=$5
file=/etc/hosts
-changes=0
if [ -z "$client_name" ]; then
logger -s -t on-dhcp-event "Client name was empty, using MAC \"$client_mac\" instead"
@@ -44,13 +43,11 @@ case "$action" in
fi
# add host
/usr/bin/vyos-hostsd-client --add-hosts --tag "DHCP-$client_ip" --host "$client_fqdn_name,$client_ip"
- ((changes++))
;;
release) # delete mapping for released address
# delete host
/usr/bin/vyos-hostsd-client --delete-hosts --tag "DHCP-$client_ip"
- ((changes++))
;;
*)
@@ -59,15 +56,6 @@ case "$action" in
;;
esac
-if [ $changes -gt 0 ]; then
- echo Success
- pid=`pgrep pdns_recursor`
- if [ -n "$pid" ]; then
- sudo rec_control --socket-dir=/run/powerdns reload-zones
- fi
-else
- echo No changes made
-fi
exit 0