2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 23:28:19 +00:00
Files
xcat-core/xCAT-server/sbin/makenamed.conf
T
Daniel Hilst 74c82463de docs(xcat-server): the Ubuntu service node comments retold the incident
The comments added with the Ubuntu fixes carried the bug report and its
consequences: what a compute node stops at, what named answers to every query
once its working directory is unwritable, and that a failed export does not fail
the service node. The comment rules keep the invariant in the source and put the
symptom and the chain in the commit.

Each is cut to the fact the code cannot show: that the resolv.conf a
systemd-resolved host publishes holds a stub pointing back at this named, that
named must be able to write the directory it drops privileges into, that apt
refuses an unsigned repository, and that re-exporting a mount needs an fsid.

service.subiquity.tmpl keeps its header, which is identical to the sibling
compute template and should stay that way.

No executable line changes.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-09-29 19:40:25 -03:00

129 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
# is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu.
# Using required /etc/lsb-release file, instead of optional lsb_release command.
is_lsb_ubuntu ()
{
awk '
(match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line
id = substr($0, RLENGTH + 1) # Save its value
}
END {
# Examine last DISTRIB_ID value to see if Ubuntu indicated
if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) {
exit 0 # Ubuntu
}
exit 1 # Not Ubuntu
}
' "${1:-/etc/lsb-release}" >/dev/null 2>&1
# Routine exit status is exit status of the last command -- the awk script.
#
# Note: if /etc/lsb-release does not exist, the exit status indicates
# failure (not Ubuntu), which is the correct outcome.
}
# forwarder_addresses [<resolv.conf> [<systemd-resolved uplink>]]
#
# The addresses named must forward to, one per line.
#
# A loopback address is not a forwarder: under systemd-resolved /etc/resolv.conf holds the
# 127.0.0.53 stub, and that stub points back at this named. The real servers are in the
# systemd-resolved uplink file.
forwarder_addresses()
{
_fa_resolv=${1:-/etc/resolv.conf}
_fa_uplink=${2:-/run/systemd/resolve/resolv.conf}
_fa_addrs=$(_fa_usable "$_fa_resolv")
if [ -z "$_fa_addrs" ]; then
_fa_addrs=$(_fa_usable "$_fa_uplink")
fi
[ -n "$_fa_addrs" ] && printf '%s\n' "$_fa_addrs"
return 0
}
_fa_usable()
{
[ -r "$1" ] || return 0
awk '$1 == "nameserver" && $2 !~ /^127\./ && $2 != "::1" { print $2 }' "$1" 2>/dev/null
}
# named_directory [<lsb-release> [<os-release> [<SuSE-release>]]]
#
# The working directory for named. It must be writable by the user named drops to: Debian runs
# it as "bind" and ships /var/cache/bind, while /var/named is created root-owned.
named_directory()
{
_nd_lsb=${1:-/etc/lsb-release}
_nd_os=${2:-/etc/os-release}
_nd_suse=${3:-/etc/SuSE-release}
if is_lsb_ubuntu "$_nd_lsb"; then
echo /var/cache/bind
return 0
fi
if [ -f "$_nd_suse" ] || grep -s -q sles "$_nd_os"; then
echo /var/lib/named
return 0
fi
echo /var/named
}
# A test loads this file for the routines above, so the rest must not run on a require.
[ "${MAKENAMED_LIB:-}" = 1 ] && return 0
DIRECTORY=$(named_directory)
FILE=/etc/named.conf
if ( is_lsb_ubuntu ); then
FILE=/etc/bind/named.conf
fi
#unalias cp
if [ -f $FILE ]; then
cp -f $FILE ${FILE}.ORIG
fi
if [ ! -d $DIRECTORY ]; then
mkdir $DIRECTORY
fi
echo "options {
directory \"$DIRECTORY\";
dump-file \"$DIRECTORY/data/cache_dump.db\";
statistics-file \"$DIRECTORY/data/named_stats.txt\";
memstatistics-file \"$DIRECTORY/data/named_mem_stats.txt\";
recursion yes;
forward only;
forwarders {" >$FILE
forwarder_addresses | while read -r i
do
echo " $i;"
done >>$FILE
echo " };" >>$FILE
# Natural version compare against version of bind.
version_ge()
{
if [ -z "$1" ] || [ -z "$2" ]; then
return 1
fi
# "sort --version-sort" sorts versions in ascending order.
[ "$(printf '%s\n' "$1" "$2" | sort --version-sort | tail -n1)" = "$1" ]
}
BIND_VERSION=$(/usr/sbin/named -v | cut -d" " -f2 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
if version_ge "$BIND_VERSION" "9.16.6"; then
if ! version_ge "$BIND_VERSION" "9.18.0"; then
echo " dnssec-enable no;" >>$FILE
fi
echo " dnssec-validation no;" >>$FILE
fi
echo "};" >>$FILE