Make cluster_setup.sh use generated configuration file
authorMartin Schwenke <martin@meltin.net>
Tue, 29 Jul 2014 02:56:42 +0000 (12:56 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 12 Aug 2014 01:22:13 +0000 (11:22 +1000)
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 <martin@meltin.net>
autocluster
base/all/root/scripts/cluster_setup.sh
base/all/root/scripts/tasks/install_clusterfs_gpfs.sh
base/all/root/scripts/tasks/install_extra_packages.sh
base/all/root/scripts/tasks/setup_cluster_nas.sh
base/all/root/scripts/tasks/setup_clusterfs_gpfs.sh
base/all/root/scripts/tasks/setup_node_ad.sh

index 30bce13a1e06ab8f282d4551fcc71c36e35ec693..2d8a8af7fa2b96fe2c5902622cdc3bd70acca584 100755 (executable)
@@ -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 ] && {
index 4009727bb742b82974e6086bab992bbb995d117f..6a32c13f016edc4bc42e12499e8213bebcd79d02 100755 (executable)
@@ -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
index e740eeddf409754239b4ec975df47e37f2015007..f12473d965dc3886b21fcfbccb1832e39566ac5e 100755 (executable)
@@ -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
index 11b846b0d62f845ead89285730a12d83a55e423d..39140dad900f4b2b32ad0f3067a50d2fddcb1eb4 100755 (executable)
@@ -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
index 3b6981822886df9d0998d816058d3e0d7ce8f664..d97011896f18c2dcf5e7945876bf034bd2321205 100755 (executable)
@@ -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 ()
index 90f4492b96cadf8c450354c90973f155bae4b6bd..9c546dd5a6ca470edff09afe1aac5ff7e4ae62da 100755 (executable)
@@ -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")
 
index 2077b7ff3be8008b68322528996c83482ef98f92..e8ceac761cdabd306d33297bf9a4cd4b121811be 100755 (executable)
@@ -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 <<EOF
@@ -45,7 +45,7 @@ EOF
 mkdir /var/run/samba
 
 # Add NetBIOS name to hosts
-echo "$hostip @@AD_NETBIOS_NAME@@.@@DOMAIN@@ @@AD_NETBIOS_NAME@@" >>/etc/hosts
+echo "${hostip} ${AD_NETBIOS_NAME}.${DOMAIN} ${AD_NETBIOS_NAME}" >>/etc/hosts
 
 # Update DNS configuration
 echo "Updating /etc/resolv.conf"