Rework cluster_setup() to use node types instead of $CLUSTER_TYPE
[tridge/autocluster.git] / base / all / root / scripts / setup_cluster_nas.sh
1 #!/bin/bash
2
3 # Configure a simple NAS cluster as generated by autocluster..
4
5 set -e
6
7 conf_file="/root/scripts/nas.conf"
8
9 ad_admin_pass="@@AD_ADMIN_PASS@@"
10 domain_auth="administrator${ad_admin_pass:+%}${ad_admin_pass}"
11
12 wait_until_healthy ()
13 {
14     local timeout="${1:-120}"
15
16     echo -n "Wait until healthy [<${timeout}] "
17
18     local count=0
19     while [ $count -lt $timeout ] ; do
20         if ctdb nodestatus all >/dev/null ; then
21             echo "[${count}]"
22             return 0
23         fi
24         echo -n "."
25         count=$(($count + 1))
26         sleep 1
27     done
28
29     echo "[TIMEOUT]"
30     return 1
31 }
32
33 auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file")
34
35 case "$auth_type" in
36     winbind)
37         echo "Joining domain"
38         net ads join -U"$domain_auth"
39         ;;
40 esac
41
42 echo "Restarting ctdb (up to 5 times)"
43 # Just in case the cluster doesn't become healthy the first time,
44 # repeat a few times...
45 for i in $(seq 1 5) ; do
46     onnode -p all "service ctdb restart"
47     if wait_until_healthy ; then
48         echo "NAS cluster setup complete"
49         exit 0
50     fi
51 done
52
53 exit 1