Don't manually mess with ntpd, just enable it in kickstart
[autocluster.git] / base / all / root / scripts / setup_cluster.sh
1 #!/bin/bash
2
3 # Configure a simple NAS cluster as generated by autocluster..
4
5 set -e
6
7 domain_auth="administrator"
8 auth_type="files"
9
10 conf_file="/root/scripts/nas.conf"
11
12 . /root/scripts/functions
13
14 ####################
15 # show program usage
16 usage ()
17 {
18     cat >&2 <<EOF
19 Usage: setup_samba.sh [OPTION] 
20   options:
21     -x                        enable script debugging
22     -c config_file            config file to load
23     -U username%password      domain authentication
24 EOF
25     exit 1
26 }
27
28
29 ############################
30 # parse command line options
31 temp=$(getopt -n "$prog" -o "axhU:c:" -l help -- "$@")
32 [ $? != 0 ] && usage
33 eval set -- "$temp"
34 while true ; do
35     case "$1" in
36         -x) set -x; shift ;;
37         -c) conf_file="$2"   ; shift 2 ;;
38         -U) domain_auth="$2" ; shift 2 ;;
39         --) shift ; break ;;
40         -h|--help|*) usage ;;
41     esac
42 done
43
44 auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file")
45
46 case "$auth_type" in
47     winbind|files) : ;;
48     *)
49         echo "Unsupported authentication type \"${auth_type}\""
50         usage
51 esac
52
53 domain=$(sed -r -n -e 's@^domain[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file" | tr '[a-z]' '[A-Z]')
54
55 kdc=$(sed -r -n -e 's@^kdc[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file")
56
57 mmgetstate | grep active > /dev/null || {
58     echo "GPFS must be running to setup Samba"
59     exit 1
60 }
61
62 echo "Enabling ctdb..."
63 onnode -p all chkconfig ctdb on
64
65 case "$auth_type" in
66     winbind)
67         echo "Setting up NSS, PAM, KRB5..."
68         onnode -p all authconfig --update --nostart \
69             --enablewinbindauth --enablewinbind \
70             --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
71         ;;
72     files)
73         echo "Setting up NSS, PAM, KRB5..."
74         onnode -p all authconfig --update --nostart \
75             --disablewinbindauth --disablewinbind \
76             --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
77         ;;
78 esac
79
80 echo "Configuring services..."
81 onnode -p all "(cd scripts/cluster_configure && \
82     ./cluster-configure.py -t 'templates/rhel/' -vv '$conf_file')"
83
84 case "$auth_type" in
85     winbind)
86         echo "Joining domain"
87         net ads join -U"$domain_auth"
88         ;;
89 esac
90
91 echo "Restarting ctdb"
92 onnode -p all "service ctdb restart"
93
94 # let's hit this with a big hammer...
95 for i in $(seq 1 5) ; do
96     echo "Waiting until healthy"
97     wait_until_healthy 60 && break
98     echo "Nope, restart ctdb..."
99     onnode -p all "service ctdb restart"
100 done
101
102 echo "Waiting for cluster to become healthy"
103 wait_until_healthy
104
105 echo "Setup done"