New configuration variable AD_DNS_FORWARDER
[amitay/autocluster.git] / base / all / root / scripts / tasks / setup_clusterfs_gpfs.sh
1 #!/bin/sh
2
3 # Automatically setup GPFS.  This is a quick way to get setup with an
4 # autocluster system.  It finds NSDs, does various pieces of GPFS
5 # configuration, creates a filesystem and mounts it.
6
7 set -e
8
9 gpfs_num_nsds="@@GPFS_DEFAULT_NSDS@@"
10 cluster_name="@@CLUSTER@@"
11 mountpoint="@@CLUSTERFS_DEFAULT_MOUNTPOINT@@"
12 nodes_storage_gpfs="@@NODES_STORAGE_GPFS@@"
13 shared_disk_ids="@@SHARED_DISK_IDS@@"
14
15 dir=$(dirname "$0")
16
17 ##################################################
18
19 # If there are "storage_gpfs" nodes in the cluster (meaning that "nas"
20 # nodes will not have direct-attached storage) then scripts that
21 # include this snippet must be run on one of the storage nodes.
22 # Therefore, in the case, this snippet tries to determine if it is
23 # running on the 1st GPFS storage node and, if not, attempts to run
24 # the script there.
25 if [ -n "$nodes_storage_gpfs" -a \
26     "${HOSTNAME%%.*}" != "${nodes_storage_gpfs%%[.,]*}" ] ; then
27     if [ "${0#/}" != "$0" ] ; then
28         script="$0"
29     else
30         script="${PWD}/${0}"
31     fi
32     re_exec_node="${nodes_storage_gpfs%%[.,]*}"
33     echo
34     echo "Creating NSDs on node \"${re_exec_node}\""
35     exec ssh "$re_exec_node" "$script" "$@"
36 fi
37
38 ##################################################
39
40 # Uses: cluster_name
41 gpfs_setup ()
42 {
43     _domain=$(dnsdomainname)
44     _nodes=$(onnode -q all hostname | grep -i "$_domain" | tr 'A-Z\012' 'a-z\040')
45
46     _first="${_nodes%% *}"
47
48     # Determine primary and secondary nodes.  Give preference to GPFS
49     # storage nodes, falling back to regular nodes if there aren't any
50     # or aren't enough.
51     if [ -n "$nodes_storage_gpfs" ] ; then
52         _primary="${nodes_storage_gpfs%%,*}"
53         _rest="${nodes_storage_gpfs#*,}"
54         _secondary="${_rest%%,*}"
55     fi
56     if [ -z "$_primary" ] ; then
57         _primary="$_first"
58         _rest="${_nodes#* }"
59         _secondary="${_rest%% *}"
60     elif [ -z "$_secondary" ] ; then
61         _secondary="$_first"
62     fi
63
64     # Create the node description file for mmcrcluster.  If there are
65     # dedicated storage nodes then they are quorum nodes, along with
66     # the first node.  If there are no dedicated storage nodes then
67     # all nodes are quorum nodes.
68     _nodefile="${dir}/gpfs_nodes.${cluster_name}"
69     {
70         for _n in $_nodes ; do
71             if [ "$_n" = "$_first" ] ; then
72                 echo "${_n}:manager-quorum:"
73             elif [ -n "$nodes_storage_gpfs" ] ; then
74                 echo "${_n}:manager:"
75             else
76                 echo "${_n}:manager-quorum:"
77             fi
78         done
79         for _n in $(echo "$nodes_storage_gpfs" | sed -e 's@,@ @g') ; do
80             echo "${_n}:manager-quorum:"
81         done
82     } >"$_nodefile"
83
84     echo "Creating cluster"
85     # Don't quote secondary, since it might not exist
86     mmcrcluster -N "$_nodefile" \
87         -p "$_primary" ${_secondary:+-s} $_secondary \
88         -r /usr/bin/ssh -R /usr/bin/scp -C "${cluster_name}.${_domain}"
89
90     # GPFS >= 3.3 needs this.  Earlier versions don't have
91     # mmchlicense, so be careful.
92     if type mmchlicense >/dev/null 2>&1 ; then
93         echo
94         echo "Attempting to set server license mode for all nodes"
95         mmchlicense server --accept  -N all
96     fi
97
98     echo
99     echo "Attempting to set adminMode=allToAll"
100     mmchconfig adminMode=allToAll </dev/null  || true
101
102     echo
103     echo "Generating auth key"
104     mmauth genkey new
105
106     echo
107     echo "Setting GPFS config options"
108     mmchconfig autoload=yes,leaseRecoveryWait=3,maxFilesToCache=20000,failureDetectionTime=10,maxMBpS=500,unmountOnDiskFail=yes,pagepool=64M,allowSambaCaseInsensitiveLookup=no,cipherList=AUTHONLY
109
110     echo "Starting gpfs"
111     mmstartup -a
112
113     echo "Waiting for gpfs to become active"
114     _count=0
115     while  mmgetstate -a | tail -n +4 | grep -v " active" > /dev/null; do
116         echo -n "."
117         _count=$(($_count + 1))
118         if [ $_count -gt 60 ] ; then
119             echo "TIMEOUT: gpfs didn't become active"
120             exit 1
121         fi
122         sleep 1
123     done
124     echo
125 }
126
127 nsdfile="${dir}/gpfs_nsds_all.${cluster_name}"
128
129 # Uses: nodes_storage_gpfs
130 # Sets: nsdfile
131 gpfs_mknsd ()
132 {
133     echo
134     echo "Setting up NSDs"
135
136     # Create an extended regexp that matches any of the IDs
137     pat=$(echo "$shared_disk_ids" | sed -e 's@  *@|@g')
138
139     # Now get devices and names from multipath
140     multipath -dl |
141     sed -r -n -e "s@^[^[:space:]]+[[:space:]]+\(($pat)\)[[:space:]](dm-[^[:space:]]+).*@\1 \2@p" |
142     while read _name _disk ; do
143         _name=$(echo "$_name" | tr -d -c '[:alnum:]')
144         echo "${_disk}:${nodes_storage_gpfs}::dataAndMetadata:1:${_name}:"
145     done >"$nsdfile"
146
147     mmcrnsd -F "$nsdfile"
148     mmlsnsd -m
149 }
150
151 # Uses: mountpoint, gpfs_num_nsds, nsdfile
152 gpfs_mkfs ()
153 {
154     echo
155     echo "Creating filesystem"
156
157     if [ ! -r "$nsdfile" ] ; then
158         echo "ERROR: missing NSD file \"${nsdfile}\""
159         exit 1
160     fi
161
162     mkdir -p "${mountpoint}/automountdir"
163
164     nsdfile2="${dir}/gpfs_nsds_defaultfs.${cluster_name}"
165     if [ -n "$gpfs_num_nsds" ] ; then
166         head -n $(($gpfs_num_nsds * 2))
167     else
168         cat
169     fi <"$nsdfile" >"$nsdfile2"
170
171     chattr +i "$mountpoint"
172
173     mmcrfs gpfs0 -F "$nsdfile2" \
174         -A yes -Q yes -D nfs4 -B 64k -k nfs4 -n 32 -E yes -S no \
175         -T "$mountpoint" -i 512
176
177     rm -f "$nsdfile2"
178 }
179
180 gpfs_mount ()
181 {
182     echo
183     echo "Mounting filesystem"
184     mmmount gpfs0 -a
185
186     echo "Waiting for gpfs to mount"
187     while ! mount | grep /dev/gpfs0 > /dev/null; do
188         echo -n "."
189         sleep 1
190     done
191
192     echo
193 }
194
195 gpfs_complete ()
196 {
197     echo "GPFS setup complete"
198 }
199
200 [ -n "$1" ] || set -- setup mknsd mkfs mount complete
201
202 for action ; do
203     gpfs_$action
204 done