summaryrefslogtreecommitdiffstats
path: root/autocluster
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-07-24 16:19:02 +1000
committerMartin Schwenke <martin@meltin.net>2014-07-24 16:19:02 +1000
commit6cf18ca7f81975e3e6dd608bfb8e639609f24775 (patch)
tree7851cee7854a2125f710117fafcc890a2a4bceeb /autocluster
parent1679eda2d77a1a6ec377f3534343089ac7442910 (diff)
downloadautocluster-6cf18ca7f81975e3e6dd608bfb8e639609f24775.tar.gz
autocluster-6cf18ca7f81975e3e6dd608bfb8e639609f24775.tar.xz
autocluster-6cf18ca7f81975e3e6dd608bfb8e639609f24775.zip
Fix broken hosts file updating
Replace the hardcoded node name regexp with a generated one. Detailed comments are required to describe the construction of the new regexp. Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'autocluster')
-rwxr-xr-xautocluster19
1 files changed, 18 insertions, 1 deletions
diff --git a/autocluster b/autocluster
index f3f0552..94d942e 100755
--- a/autocluster
+++ b/autocluster
@@ -549,7 +549,24 @@ cluster_update_hosts ()
[ -n "$hosts_file" ] || hosts_file="tmp/hosts.${CLUSTER}"
[ -r "$hosts_file" ] || die "Missing hosts file \"${hosts_file}\""
- local pat="# autocluster ${CLUSTER}\$|[[:space:]]${CLUSTER}(n|base)[[:digit:]]+"
+ # Building a general node name regexp is a bit cumbersome. :-)
+ local name_regexp="("
+ for i in $(set | sed -n -e "s@^\(node_name_format_.*\) ().*@\1@p") ; do
+ # For each node_name_format_* function, get the actual node
+ # name format string
+ fmt=$($i)
+ # fill it with placeholders (remembering that "_" is not valid
+ # in a real cluster name)
+ local t=$(printf "$fmt\n" "_" "0" | head -n 1)
+ # now replace the placeholders with regexps - order is
+ # important here, since the cluster name can contain digits
+ t=$(sed -r -e "s@[[:digit:]]+@[[:digit:]]+@" -e "s@_@${CLUSTER}@" <<<"$t")
+ # add to the regexp
+ name_regexp="${name_regexp}${t}|"
+ done
+ name_regexp="${name_regexp}${CLUSTER}n[[:digit:]]+)"
+
+ local pat="# autocluster ${CLUSTER}\$|[[:space:]]${name_regexp}"
local t="/etc/hosts.${CLUSTER}"
grep -E "$pat" /etc/hosts >"$t" || true