Fix host checking (#1052)

* Fix host checking

* nameserver -> nameservice
This commit is contained in:
Tim Wilkinson 2024-01-03 00:45:49 -08:00 committed by GitHub
parent 8b1b973490
commit 185d6e0abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 30 deletions

View File

@ -39,7 +39,7 @@ require("aredn.services")
local cursor = uci.cursor()
-- Current nameserver state
-- Current nameservice state
local ns = cursor:get_all("olsrd", "nameservice")
if not ns then
print("Missing nameservice")
@ -51,13 +51,10 @@ do
cnames[name] = true
end
local chosts = {}
for _, v in ipairs(ns.hosts or {})
do
local ip, name = v:match("^(%d+%.%d+%.%d+%.%d+)%s+(%S+)$")
if ip then
chosts[ip] = name
end
end
for _, iphost in ipairs(ns.hosts or {})
do
chosts[iphost] = true
end
local cservices = {}
for _, service in ipairs(ns.service or {})
do
@ -75,13 +72,14 @@ do
nnames = true
end
end
local nhosts = {}
local nhosts = false
for _, host in ipairs(hosts)
do
if chosts[host.ip] then
chosts[host.ip] = nil
local iphost = host.ip .. " " .. host.host
if chosts[iphost] then
chosts[iphost] = nil
else
nhosts[host.ip] = host.host
nhosts = true
end
end
local nservices = false
@ -106,22 +104,19 @@ local change = false
-- Apply the changes
if nnames or not_empty(cnames) then
cursor:set("olsrd", "nameserver", "name", names)
cursor:set("olsrd", "nameservice", "name", names)
change = true
end
if not_empty(chosts) or not_empty(nhosts) then
for k, _ in pairs(chosts)
if nhosts or not_empty(chosts) then
for i, host in ipairs(hosts)
do
cursor:delete("olsrd", "nameserver", k)
end
for k, v in pairs(nhosts)
do
cursor:set("olsrd", "nameserver", k, v)
hosts[i] = host.ip .. " " .. host.host
end
cursor:set("olsrd", "nameservice", "hosts", hosts)
change = true
end
if nservices or not_empty(cservices) then
cursor:set("olsrd", "nameserver", "service", services)
cursor:set("olsrd", "nameservice", "service", services)
change = true
end
@ -129,7 +124,7 @@ end
if change then
cursor:commit("olsrd")
print("Change")
os.execute("/etc/init.d/olsrd restart > /dev/null 2>&1")
os.execute("/usr/local/bin/restart-services.sh --force olsrd")
else
print("Unchange")
end

View File

@ -36,17 +36,23 @@ LICENSE
ROOT="/tmp/reboot-required"
SERVICES="system firewall network wireless dnsmasq tunnels manager olsrd"
# Anything to do?
if [ ! -d $ROOT ]; then
exit 0
fi
ignore=0
force=0
if [ "$1" = "--force" ]; then
shift
ignore=1
force=1
fi
if [ "$1" = "--ignore-reboot" ]; then
shift
ignore=1
fi
# Anything to do?
if [ ! -d $ROOT -a $force = 0 ]; then
exit 0
fi
# If we have to reboot, do nothing (unless ignored)
if [ -f $ROOT/reboot -a $ignore = 0 ]; then
exit 1
@ -59,7 +65,7 @@ fi
for srv in $SERVICES
do
if [ -f $ROOT/$srv ]; then
if [ -f $ROOT/$srv -o $force = 1 ]; then
echo "Restarting $srv"
if [ $srv = "tunnels" ]; then
/etc/init.d/vtund restart > /dev/null 2>&1
@ -69,11 +75,11 @@ do
elif [ -x /etc/init.d/$srv ]; then
/etc/init.d/$srv restart > /dev/null 2>&1
fi
rm $ROOT/$srv
rm -f $ROOT/$srv
fi
done
rmdir --ignore-fail-on-non-empty $ROOT
rmdir --ignore-fail-on-non-empty $ROOT 2> /dev/null
if [ -d $ROOT ]; then
exit 1
fi