From 63146672403dbdf1d8e29a71f047d6221ccbb309 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 29 Jul 2014 12:56:42 +1000 Subject: Make cluster_setup.sh use generated configuration file An early step in making cluster_setup.sh independent of autocluster. * autocluster generates cluster_setup.config during base setup * cluster_setup.sh sources this configuration file * cluster_setup.sh sources the per-task scripts * cluster_setup.sh now exits on first error * Replace @@ templates in scripts with variable references Signed-off-by: Martin Schwenke --- autocluster | 28 ++++++++++++++++++++++ base/all/root/scripts/cluster_setup.sh | 16 +++++++++---- .../root/scripts/tasks/install_clusterfs_gpfs.sh | 2 +- .../root/scripts/tasks/install_extra_packages.sh | 2 +- base/all/root/scripts/tasks/setup_cluster_nas.sh | 2 +- .../all/root/scripts/tasks/setup_clusterfs_gpfs.sh | 10 ++++---- base/all/root/scripts/tasks/setup_node_ad.sh | 18 +++++++------- 7 files changed, 57 insertions(+), 21 deletions(-) diff --git a/autocluster b/autocluster index 30bce13..2d8a8af 100755 --- a/autocluster +++ b/autocluster @@ -1008,6 +1008,34 @@ EOF register_hook setup_base_hooks setup_network +setup_base_cluster_setup_config () +{ + local f + { + echo "# Generated by autocluster" + echo + # This is a bit of a hack. Perhaps these script belong + # elsewhere, since they no longer have templates? + for f in $(find "${BASE_TEMPLATES}/all/root/scripts" -type f | + xargs grep -l '^#config:') ; do + + b=$(basename "$f") + echo "# $b" + local vs v + vs=$(sed -n 's@^#config: *@@p' "$f") + for v in $vs ; do + # This could substitute the values in directly using + # ${!v} but then no sanity checking is done to make + # sure variables are set. + echo "${v}=\"@@${v}@@\"" + done + echo + done + } | diskimage substitute_vars - "/root/scripts/cluster_setup.config" +} + +register_hook setup_base_hooks setup_base_cluster_setup_config + setup_timezone() { [ -z "$TIMEZONE" ] && { [ -r /etc/timezone ] && { diff --git a/base/all/root/scripts/cluster_setup.sh b/base/all/root/scripts/cluster_setup.sh index 4009727..6a32c13 100755 --- a/base/all/root/scripts/cluster_setup.sh +++ b/base/all/root/scripts/cluster_setup.sh @@ -2,6 +2,8 @@ #config: CLUSTERFS_TYPE +set -e + stage="$1" ; shift prefix="$stage" @@ -13,13 +15,18 @@ case "$stage" in ;; esac - dn=$(dirname $0) +config="${dn}/cluster_setup.config" +if [ ! -r "$config" ] ; then + echo "Can not local configuration file \"${config}\"" +fi +. "$config" + for task ; do case "$task" in clusterfs) - type="@@CLUSTERFS_TYPE@@" + type="$CLUSTERFS_TYPE" file="${prefix%_clusterfs}_clusterfs_${type}.sh" ;; *) @@ -28,7 +35,7 @@ for task ; do path="${dn}/tasks/${file}" - if [ ! -x "$path" ] ; then + if [ ! -r "$path" ] ; then echo "Unable to find script \"${file}\" for stage \"${stage}\" task \"${task}\"" exit 1 fi @@ -36,5 +43,6 @@ for task ; do echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" printf "%% %-66s %%\n" "Stage \"${stage}\", task \"${task}\" on host ${HOSTNAME%%.*}" echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" - "$path" + set -- # pass no arguments + . "$path" done diff --git a/base/all/root/scripts/tasks/install_clusterfs_gpfs.sh b/base/all/root/scripts/tasks/install_clusterfs_gpfs.sh index e740eed..f12473d 100755 --- a/base/all/root/scripts/tasks/install_clusterfs_gpfs.sh +++ b/base/all/root/scripts/tasks/install_clusterfs_gpfs.sh @@ -5,7 +5,7 @@ # Must force the base GPFS package first, due to the way GPFS updates # work. echo "Installing GPFS base" -yum -y install gpfs.base-@@GPFS_BASE_VERSION@@.@@RHEL_ARCH@@ +yum -y install "gpfs.base-${GPFS_BASE_VERSION}.${RHEL_ARCH}" echo "Updating GPFS base" yum -y update diff --git a/base/all/root/scripts/tasks/install_extra_packages.sh b/base/all/root/scripts/tasks/install_extra_packages.sh index 11b846b..39140da 100755 --- a/base/all/root/scripts/tasks/install_extra_packages.sh +++ b/base/all/root/scripts/tasks/install_extra_packages.sh @@ -5,7 +5,7 @@ echo "Updating from YUM repositories" yum -y update -extra_packages="@@CONFIG_EXTRA_PACKAGES@@" +extra_packages="$CONFIG_EXTRA_PACKAGES" if [ -n "$extra_packages" ] ; then echo "Installing extra packages" yum -y install $extra_packages diff --git a/base/all/root/scripts/tasks/setup_cluster_nas.sh b/base/all/root/scripts/tasks/setup_cluster_nas.sh index 3b69818..d970118 100755 --- a/base/all/root/scripts/tasks/setup_cluster_nas.sh +++ b/base/all/root/scripts/tasks/setup_cluster_nas.sh @@ -8,7 +8,7 @@ set -e conf_file="/root/scripts/nas.conf" -ad_admin_pass="@@AD_ADMIN_PASS@@" +ad_admin_pass="$AD_ADMIN_PASS" domain_auth="administrator${ad_admin_pass:+%}${ad_admin_pass}" wait_until_healthy () diff --git a/base/all/root/scripts/tasks/setup_clusterfs_gpfs.sh b/base/all/root/scripts/tasks/setup_clusterfs_gpfs.sh index 90f4492..9c546dd 100755 --- a/base/all/root/scripts/tasks/setup_clusterfs_gpfs.sh +++ b/base/all/root/scripts/tasks/setup_clusterfs_gpfs.sh @@ -9,11 +9,11 @@ set -e -gpfs_num_nsds="@@GPFS_DEFAULT_NSDS@@" -cluster_name="@@CLUSTER@@" -mountpoint="@@CLUSTERFS_DEFAULT_MOUNTPOINT@@" -nodes_storage_gpfs="@@NODES_STORAGE_GPFS@@" -shared_disk_ids="@@SHARED_DISK_IDS@@" +gpfs_num_nsds="$GPFS_DEFAULT_NSDS" +cluster_name="$CLUSTER" +mountpoint="$CLUSTERFS_DEFAULT_MOUNTPOINT" +nodes_storage_gpfs="$NODES_STORAGE_GPFS" +shared_disk_ids="$SHARED_DISK_IDS" dir=$(dirname "$0") diff --git a/base/all/root/scripts/tasks/setup_node_ad.sh b/base/all/root/scripts/tasks/setup_node_ad.sh index 2077b7f..e8ceac7 100755 --- a/base/all/root/scripts/tasks/setup_node_ad.sh +++ b/base/all/root/scripts/tasks/setup_node_ad.sh @@ -9,22 +9,22 @@ set -e rm -f /etc/samba/smb.conf # Create AD instance -echo "Provisioning Samba4 AD domain: @@DOMAIN@@" -hostip="@@NETWORK_PRIVATE_PREFIX@@.@@IPNUM@@" +echo "Provisioning Samba4 AD domain: ${DOMAIN}" +hostip="${NETWORK_PRIVATE_PREFIX}.${IPNUM}" samba-tool domain provision \ - --realm="@@DOMAIN@@" \ - --domain="@@WORKGROUP@@" \ + --realm="$DOMAIN" \ + --domain="$WORKGROUP" \ --host-ip="$hostip" \ - --host-name="@@AD_NETBIOS_NAME@@" \ + --host-name="$AD_NETBIOS_NAME" \ --server-role="domain controller" \ - --function-level="@@AD_FUNCTION_LEVEL@@" \ + --function-level="$AD_FUNCTION_LEVEL" \ --dns-backend="SAMBA_INTERNAL" # Add samba configuration parameters sed -i -e '/server services/a\ allow dns updates = True\ nsupdate command = nsupdate\ - dns forwarder = @@AD_DNS_FORWARDER@@\ + dns forwarder = ${AD_DNS_FORWARDER}\ dns recursive queries = Yes' /etc/samba/smb.conf # Add users/groups @@ -34,7 +34,7 @@ samba-tool domain passwordsettings set --complexity=off samba-tool user add test test01 samba-tool user setexpiry --noexpiry Administrator samba-tool user setexpiry --noexpiry test -samba-tool user setpassword administrator --newpassword="@@AD_ADMIN_PASS@@" +samba-tool user setpassword administrator --newpassword="$AD_ADMIN_PASS" # Samba start-up cat >> /etc/rc.d/rc.local <>/etc/hosts +echo "${hostip} ${AD_NETBIOS_NAME}.${DOMAIN} ${AD_NETBIOS_NAME}" >>/etc/hosts # Update DNS configuration echo "Updating /etc/resolv.conf" -- cgit