#!/bin/bash #config: AD_ADMIN_PASS # Configure a simple NAS cluster as generated by autocluster.. set -e conf_file="/root/scripts/nas.conf" ad_admin_pass="$AD_ADMIN_PASS" domain_auth="administrator${ad_admin_pass:+%}${ad_admin_pass}" wait_until_healthy () { local timeout="${1:-120}" echo -n "Wait until healthy [<${timeout}] " local count=0 while [ $count -lt $timeout ] ; do if ctdb nodestatus all >/dev/null ; then echo "[${count}]" return 0 fi echo -n "." count=$(($count + 1)) sleep 1 done echo "[TIMEOUT]" return 1 } auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file") case "$auth_type" in winbind) echo "Joining domain" timeout 10 net ads join -U"$domain_auth" || \ { echo "Domain join failed"; exit 1; } ;; esac 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 onnode -p all "service ctdb restart" if wait_until_healthy ; then echo "NAS cluster setup complete" exit 0 fi done exit 1