Rework cluster_setup() to use node types instead of $CLUSTER_TYPE
authorMartin Schwenke <martin@meltin.net>
Mon, 30 Jun 2014 06:39:15 +0000 (16:39 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 2 Jul 2014 10:26:52 +0000 (20:26 +1000)
* Remove configuration variable CLUSTER_TYPE

* Add "build" node type

* Rename setup scripts for "ad" and "build" node type

* Separate out some setup_node_nas.sh from setup_cluster_nas.sh

* Make install_packages.sh and cluster_setup.sh more verbose

* Separate out clusterfs_setup.sh

Signed-off-by: Martin Schwenke <martin@meltin.net>
14 files changed:
autocluster
base/all/root/scripts/install_ad.sh [moved from base/all/root/scripts/install_ad_server.sh with 100% similarity]
base/all/root/scripts/install_packages.sh
base/all/root/scripts/setup_cluster.sh
base/all/root/scripts/setup_cluster_nas.sh
base/all/root/scripts/setup_clusterfs.sh [new file with mode: 0755]
base/all/root/scripts/setup_node_ad.sh [moved from base/all/root/scripts/setup_cluster_ad_server.sh with 95% similarity]
base/all/root/scripts/setup_node_build.sh [moved from base/all/root/scripts/setup_cluster_build.sh with 65% similarity]
base/all/root/scripts/setup_node_nas.sh [new file with mode: 0755]
config.d/00base.defconf
config.d/50node_nas.defconf
config.d/52node_build.defconf [new file with mode: 0644]
config.d/55node_storage_gpfs.defconf
config.d/57node_ad.defconf [moved from config.d/70ad.defconf with 61% similarity]

index e885037..6793f8c 100755 (executable)
@@ -596,46 +596,67 @@ cluster_boot ()
     echo ""
 }
 
+cluster_setup_tasks_DEFAULT ()
+{
+    local stage="$1"
+
+    # By default nodes have no tasks
+    case "$stage" in
+       install_packages) echo "" ;;
+       setup_clusterfs)  echo "" ;;
+       setup_node)       echo "" ;;
+       setup_cluster)    echo "" ;;
+    esac
+}
+
 cluster_setup ()
 {
     announce "cluster setup \"${CLUSTER}\""
     [ -n "$CLUSTER" ] || die "\$CLUSTER not set"
 
-    local install_tasks=""
-    local setup_tasks=""
-
-    case "$CLUSTER_TYPE" in
-       "build")
-           install_tasks="clusterfs build"
-           setup_tasks="build"
-           ;;
-       "ad")
-           install_tasks="ad_server"
-           setup_tasks="ad_server"
-           ;;
-       "samba")
-           install_tasks="clusterfs nas"
-           setup_tasks="clusterfs nas"
-           ;;
-    esac
-
     local ssh="ssh -o StrictHostKeyChecking=no"
+    local setup_clusterfs_done=false
+    local setup_cluster_done=false
 
-    if [ -n "$install_tasks" ] ; then
-       [ -n "$CLUSTER_PATTERN" ] || CLUSTER_PATTERN="$CLUSTER"
+    _cluster_setup_do_stage ()
+    {
+       local stage="$1"
+       local type="$2"
+       local ip_offset="$3"
+       local name="$4"
+       local ctdb_node="$5"
+
+       local tasks=$(call_func cluster_setup_tasks "$type" "$stage")
+
+       if [ -n "$tasks" ] ; then
+           # These tasks are only done on 1 node
+           case "$stage" in
+               setup_clusterfs)
+                   if $setup_clusterfs_done ; then
+                       return
+                   else
+                       setup_clusterfs_done=true
+                   fi
+                   ;;
+               setup_cluster)
+                   if $setup_cluster_done ; then
+                       return
+                   else
+                       setup_cluster_done=true
+                   fi
+                   ;;
+           esac
 
-       local nodes=$(vircmd dominfo "$CLUSTER_PATTERN" 2>/dev/null | \
-           sed -n -e 's/Name: *//p')
+           $ssh "$name" "./scripts/${stage}.sh" $tasks
+       fi
 
-       for i in $nodes ; do
-           $ssh "$i" ./scripts/install_packages.sh $install_tasks
-       done
-    fi
+    }
 
-    if [ -n "$setup_tasks" ] ; then
-       local n1="${CLUSTER}n1"
-       $ssh "$n1" ./scripts/setup_cluster.sh $setup_tasks
-    fi
+    local stages="install_packages setup_clusterfs setup_node setup_cluster"
+    local stage
+    for stage in $stages ; do
+       for_each_node _cluster_setup_do_stage "$stage"
+    done
 }
 
 create_one_node ()
index 9b023c0..2b6a04c 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+printf "%% %-66s %%\n" "Install packages doing \"yum update\" on host ${HOSTNAME%%.*}"
+echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
 echo "Updating from YUM repositories"
 yum -y update
 
@@ -27,5 +30,8 @@ for task ; do
        exit 1
     fi
 
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+    printf "%% %-66s %%\n" "Install packages task \"${task}\" on host ${HOSTNAME%%.*}"
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
     "$path"
 done
index 2e2d7ea..93aca59 100755 (executable)
@@ -3,15 +3,7 @@
 dn=$(dirname $0)
 
 for task ; do
-    case "$task" in
-       clusterfs)
-           type="@@CLUSTERFS_TYPE@@"
-           file="setup_clusterfs_${type}.sh"
-           ;;
-       *)
-           file="setup_cluster_${task}.sh"
-    esac
-
+    file="setup_cluster_${task}.sh"
     path="${dn}/${file}"
 
     if [ ! -x "$path" ] ; then
@@ -19,5 +11,8 @@ for task ; do
        exit 1
     fi
 
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+    printf "%% %-66s %%\n" "Setup cluster task \"${task}\""
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
     "$path" || exit $?
 done
index 8f01827..aa0da82 100755 (executable)
@@ -4,11 +4,11 @@
 
 set -e
 
+conf_file="/root/scripts/nas.conf"
+
 ad_admin_pass="@@AD_ADMIN_PASS@@"
 domain_auth="administrator${ad_admin_pass:+%}${ad_admin_pass}"
 
-conf_file="/root/scripts/nas.conf"
-
 wait_until_healthy ()
 {
     local timeout="${1:-120}"
@@ -30,67 +30,8 @@ wait_until_healthy ()
     return 1
 }
 
-####################
-# show program usage
-usage ()
-{
-    cat >&2 <<EOF
-Usage: setup_samba.sh [OPTION] 
-  options:
-    -x                        enable script debugging
-    -c config_file            config file to load
-    -U username%password      domain authentication
-EOF
-    exit 1
-}
-
-
-############################
-# parse command line options
-temp=$(getopt -n "$prog" -o "axhU:c:" -l help -- "$@")
-[ $? != 0 ] && usage
-eval set -- "$temp"
-while true ; do
-    case "$1" in
-       -x) set -x; shift ;;
-       -c) conf_file="$2"   ; shift 2 ;;
-       --) shift ; break ;;
-       -h|--help|*) usage ;;
-    esac
-done
-
 auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file")
 
-case "$auth_type" in
-    winbind|files) : ;;
-    *)
-       echo "Unsupported authentication type \"${auth_type}\""
-       usage
-esac
-
-domain=$(sed -r -n -e 's@^domain[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file" | tr '[a-z]' '[A-Z]')
-
-kdc=$(sed -r -n -e 's@^kdc[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file")
-
-case "$auth_type" in
-    winbind)
-       echo "Setting up NSS, PAM, KRB5..."
-       onnode -p all authconfig --update --nostart \
-           --enablewinbindauth --enablewinbind \
-           --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
-       ;;
-    files)
-       echo "Setting up NSS, PAM, KRB5..."
-       onnode -p all authconfig --update --nostart \
-           --disablewinbindauth --disablewinbind \
-           --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
-       ;;
-esac
-
-echo "Configuring services..."
-onnode -p all "(cd scripts/cluster_configure && \
-    ./cluster-configure.py -t 'templates/rhel/' -vv '$conf_file')"
-
 case "$auth_type" in
     winbind)
        echo "Joining domain"
@@ -98,16 +39,15 @@ case "$auth_type" in
        ;;
 esac
 
-echo "Restarting ctdb"
-onnode -p all "service ctdb restart"
-
-# let's hit this with a big hammer...
+echo "Restarting ctdb (up to 5 times)"
+# Just in case the cluster doesn't become healthy the first time,
+# repeat a few times...
 for i in $(seq 1 5) ; do
-    wait_until_healthy 60 && break
-    echo "Nope, restart ctdb..."
     onnode -p all "service ctdb restart"
+    if wait_until_healthy ; then
+       echo "NAS cluster setup complete"
+       exit 0
+    fi
 done
 
-wait_until_healthy
-
-echo "Setup done"
+exit 1
diff --git a/base/all/root/scripts/setup_clusterfs.sh b/base/all/root/scripts/setup_clusterfs.sh
new file mode 100755 (executable)
index 0000000..ec7c3e9
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+dn=$(dirname $0)
+
+for task ; do
+    type="@@CLUSTERFS_TYPE@@"
+    file="setup_clusterfs_${type}.sh"
+    path="${dn}/${file}"
+
+    if [ ! -x "$path" ] ; then
+       echo "Unable to find script \"${file}\" to setup task \"${task}\""
+       exit 1
+    fi
+
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+    printf "%% %-66s %%\n" "Setup clusterfs task \"${task}\""
+    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+    "$path" || exit $?
+done
similarity index 95%
rename from base/all/root/scripts/setup_cluster_ad_server.sh
rename to base/all/root/scripts/setup_node_ad.sh
index da2cdc9..7714e8c 100755 (executable)
@@ -2,8 +2,6 @@
 
 set -e
 
-# Assume that an AD server cluster is always a single node :-)
-
 # Remove samba3 configuration file
 rm -f /etc/samba/smb.conf
 
similarity index 65%
rename from base/all/root/scripts/setup_cluster_build.sh
rename to base/all/root/scripts/setup_node_build.sh
index 64ca1a2..04d18b6 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/sh
 
-# Assume that a build cluster is always a single node :-)
-
 echo "Running rpmdev-setuptree"
 rpmdev-setuptree
 
diff --git a/base/all/root/scripts/setup_node_nas.sh b/base/all/root/scripts/setup_node_nas.sh
new file mode 100755 (executable)
index 0000000..65fd966
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# Per-node NAS cluster configuration steps
+
+set -e
+
+conf_file="/root/scripts/nas.conf"
+
+auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file")
+
+case "$auth_type" in
+    winbind|files) : ;;
+    *)
+       echo "Unsupported authentication type \"${auth_type}\""
+       usage
+esac
+
+domain=$(sed -r -n -e 's@^domain[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file" | tr '[a-z]' '[A-Z]')
+
+kdc=$(sed -r -n -e 's@^kdc[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file")
+
+case "$auth_type" in
+    winbind)
+       echo "Setting up NSS, PAM, KRB5..."
+       authconfig --update --nostart \
+           --enablewinbindauth --enablewinbind \
+           --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
+       ;;
+    files)
+       echo "Setting up NSS, PAM, KRB5..."
+       authconfig --update --nostart \
+           --disablewinbindauth --disablewinbind \
+           --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
+       ;;
+esac
+
+echo "Configuring services..."
+(cd scripts/cluster_configure && \
+    ./cluster-configure.py -t "templates/rhel/" -vv "$conf_file")
index 4f0440a..d750e33 100644 (file)
@@ -4,9 +4,6 @@
 
 # Cluster
 
-defconf CLUSTER_TYPE "samba" \
-       "samba|ad|build" "Type of cluster, for configuration stage"
-
 defconf CLUSTERFS_TYPE "gpfs" \
        "<gpfs|?>" "type of cluster filesystem to use"
 
index a0ac0c1..794c42f 100644 (file)
@@ -31,3 +31,13 @@ node_has_shared_disks_nas ()
 {
     ! have_dedicated_storage_nodes
 }
+
+cluster_setup_tasks_nas ()
+{
+    case "$1" in
+       install_packages) echo "clusterfs nas" ;;
+       setup_clusterfs)  echo "clusterfs"     ;;
+       setup_node)       echo "nas"           ;;
+       setup_cluster)    echo "nas"           ;;
+    esac
+}
diff --git a/config.d/52node_build.defconf b/config.d/52node_build.defconf
new file mode 100644 (file)
index 0000000..b375e0c
--- /dev/null
@@ -0,0 +1,22 @@
+# Hey Emacs, this is a -*- shell-script -*- !!!
+
+create_node_build ()
+{
+    local ip_offset="$1"
+    local name="$2"
+    local ctdb_node="$3"
+
+    echo "Creating build node $name"
+
+    create_node_COMMON "$name" "$ip_offset" "$type"
+}
+
+cluster_setup_tasks_build ()
+{
+    case "$1" in
+       install_packages) echo "clusterfs build" ;;
+       setup_clusterfs)  echo "" ;;
+       setup_node)       echo "build" ;;
+       setup_cluster)    echo "" ;;
+    esac
+}
index 4601714..4ed9ebd 100644 (file)
@@ -40,3 +40,13 @@ is_dedicated_storage_node_storage_gpfs ()
 {
     true
 }
+
+cluster_setup_tasks_storage_gpfs ()
+{
+    case "$1" in
+       install_packages) echo "clusterfs" ;;
+       setup_clusterfs)  echo "clusterfs" ;;
+       setup_node)       echo "" ;;
+       setup_cluster)    echo "" ;;
+    esac
+}
similarity index 61%
rename from config.d/70ad.defconf
rename to config.d/57node_ad.defconf
index 2915335..8abeade 100644 (file)
@@ -8,3 +8,13 @@ defconf AD_FUNCTION_LEVEL "2008" \
 
 defconf AD_NETBIOS_NAME "samba4" \
        "<string>" "NetBIOS name to use for AD server"
+
+cluster_setup_tasks_ad ()
+{
+    case "$1" in
+       install_packages) echo "ad"  ;;
+       setup_clusterfs)  echo ""    ;;
+       setup_node)       echo "ad"  ;;
+       setup_cluster)    echo ""    ;;
+    esac
+}