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