# Exit on 1st error.
set -e
+usage ()
+{
+ cat <<EOF
+usage: ./create_cluster.sh <cluster> [ <type> [ <args> ] ]
+ <cluster> - Name of cluster
+ <type> - Type of cluster
+ samba: samba cluster with gpfs (default)
+ build: development node
+ ad: active directory node
+ <args> - Optional arguments to autocluster"
+
+EOF
+ exit 1
+}
+
CLUSTER="$1"
+[ -n "$CLUSTER" ] || usage
+shift
+
+TYPE="$1"
+if [ -n "$TYPE" ] ; then
+ case "$TYPE" in
+ build|ad|samba) : ;;
+ *) usage ;;
+ esac
+ shift
+else
+ TYPE="samba"
+fi
-if [ -z "$CLUSTER" ] ; then
- echo "usage: ./create_cluster.sh <cluster>"
+die () {
+ echo "$@"
exit 1
-fi
+}
update_hosts_file ()
{
t="/etc/hosts.${cluster}"
grep -E "$pat" /etc/hosts >"$t"
if diff -B "$t" "tmp/hosts.${cluster}" >/dev/null ; then
- rm "$t"
- return
+rm "$t"
+return
fi
old=/etc/hosts.old.autocluster
diff -u "$old" /etc/hosts || true
}
+[ -f "${CLUSTER}.autocluster" ] || die "Missing cluster configuration file ${CLUSTER}.autocluster"
vircmd destroy "$CLUSTER" || true
-autocluster -c "${CLUSTER}.autocluster" create cluster "$CLUSTER"
+autocluster -c "${CLUSTER}.autocluster" "$@" create cluster "$CLUSTER"
update_hosts_file "$CLUSTER"
vircmd start "$CLUSTER"
-n1="${CLUSTER}n1"
+nodes=$(vircmd dominfo "$CLUSTER" 2>/dev/null | sed -n -e 's/Name: *//p')
-# Wait until the first node is up.
-waitfor "/var/log/kvm/serial.${n1}" "login:" 120
+# Wait for the node
+for i in $nodes ; do
+ waitfor "/var/log/kvm/serial.$i" "login:" 300 || {
+ vircmd destroy "$CLUSTER"
+ die "Failed to create cluster"
+ }
+done
# Run the post-install in sequence on each node. This is a little
# more time-consuming than doing it in parallel but if some nodes boot
# However, the approach used here is more flexible since a generic
# base image can be reused. Note that this might not get the correct
# nodes for some exotic clusters...
-nodes=$(sed -r -n -e "s@.*[[:space:]](${CLUSTER}n[[:digit:]]+)\$@\1@p" /etc/hosts)
-# Could avoid this by creating a special base and doing it in postinstall
-for i in $nodes ; do
- ssh -o StrictHostKeyChecking=no "$i" ./scripts/install_gpfs_nas.sh
-done
-ssh "$n1" ./scripts/setup_gpfs.sh
+n1="${CLUSTER}n1"
-ssh "$n1" ./scripts/setup_cluster.sh
+case "$TYPE" in
+ "build")
+ # Build node doesn't really need CTDB/Samba to be installed, if the
+ # packages are not present in the repo, they're skipped.
+ ssh -o StrictHostKeyChecking=no "$n1" "./scripts/setup_build.sh || true"
+ ;;
+
+ "ad")
+ ssh -o StrictHostKeyChecking=no "$n1" ./scripts/setup_ad_server.sh
+ ;;
+
+ "samba")
+ for i in $nodes ; do
+ ssh -o StrictHostKeyChecking=no "$i" ./scripts/install_gpfs_nas.sh
+ done
+ ssh "$n1" ./scripts/setup_gpfs.sh
+
+ auth_method=$(autocluster -c "${CLUSTER}.autocluster" -e 'echo $AUTH_METHOD')
+ if [ "$auth_method" = "winbind" ]; then
+ ad_pw=$(autocluster -c "${CLUSTER}.autocluster" -e 'echo $AD_ADMIN_PASS')
+ args="-UAdministrator%${ad_pw}"
+ else
+ args=""
+ fi
+ ssh "$n1" ./scripts/setup_cluster.sh "$args"
+ ;;
+esac