summaryrefslogtreecommitdiffstats
path: root/base/all/root/scripts/setup_cluster.sh
blob: cd2c9c5c8e95b31fa3439a8f1bcc16af9179c695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

# Configure a simple NAS cluster as generated by autocluster..

set -e

domain_auth="administrator"
auth_type="files"

conf_file="/root/scripts/nas.conf"

. /root/scripts/functions

####################
# show program usage
usage ()
{
    cat >&2 <<EOF
Usage: setup_samba.sh [OPTION] 
  options:
    -x                        enable script debugging
    -c config_file            config file to load
    -U username%password      domain authentication
EOF
    exit 1
}


############################
# parse command line options
temp=$(getopt -n "$prog" -o "axhU:c:" -l help -- "$@")
[ $? != 0 ] && usage
eval set -- "$temp"
while true ; do
    case "$1" in
	-x) set -x; shift ;;
	-c) conf_file="$2"   ; shift 2 ;;
	-U) domain_auth="$2" ; shift 2 ;;
	--) shift ; break ;;
	-h|--help|*) usage ;;
    esac
done

auth_type=$(sed -r -n -e 's@^auth_method[[:space:]]*=[[:space:]]*(files|winbind)[[:space:]]*$@\1@p' "$conf_file")

case "$auth_type" in
    winbind|files) : ;;
    *)
	echo "Unsupported authentication type \"${auth_type}\""
	usage
esac

domain=$(sed -r -n -e 's@^domain[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file" | tr '[a-z]' '[A-Z]')

kdc=$(sed -r -n -e 's@^kdc[[:space:]]*=[[:space:]]*([^ ]*)[[:space:]]*$@\1@p' "$conf_file")

mmgetstate | grep active > /dev/null || {
    echo "GPFS must be running to setup Samba"
    exit 1
}

echo "Enabling ctdb..."
onnode -p all chkconfig ctdb on

case "$auth_type" in
    winbind)
	echo "Setting up NSS, PAM, KRB5..."
	onnode -p all authconfig --update --nostart \
	    --enablewinbindauth --enablewinbind \
	    --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
	;;
    files)
	echo "Setting up NSS, PAM, KRB5..."
	onnode -p all authconfig --update --nostart \
	    --disablewinbindauth --disablewinbind \
	    --disablekrb5 --krb5kdc=$kdc.$domain  --krb5realm=$domain
	;;
esac

echo "Configuring services..."
onnode -p all "(cd scripts/cluster_configure && \
    ./cluster-configure.py -t 'templates/rhel/' -vv '$conf_file')"

case "$auth_type" in
    winbind)
	echo "Joining domain"
	net ads join -U"$domain_auth"
	;;
esac

echo "Restarting ctdb"
onnode -p all "service ctdb restart"

# let's hit this with a big hammer...
for i in $(seq 1 5) ; do
    echo "Waiting until healthy"
    wait_until_healthy 60 && break
    echo "Nope, restart ctdb..."
    onnode -p all "service ctdb restart"
done

echo "Waiting for cluster to become healthy"
wait_until_healthy

echo "Setup done"