Move wait_until_healthy() into setup_cluster.sh
[tridge/autocluster.git] / base / all / root / scripts / setup_gpfs.sh
1 #!/bin/bash
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 ####################
10
11 # $nsd_servers is setup in here
12 . $(dirname $0)/nsd_server_common.bash "$@"
13
14 ####################
15
16 usage ()
17 {
18     cat <<EOF
19 Usage: $0 [ OPTION ]
20   options:
21
22     --gpfs-num-nsds=<num>      Specify number of NSDs to use for GPFS
23                                filesystem.  Defaults to value of
24                                autocluster variable GPFS_DEFAULT_NSDS.
25                                If this is unset then all NSDs found
26                                are used.
27
28     --cluster-name=<string>    Specify prefix for GPFS cluster name.  The
29                                domain will be appended to this.
30                                Defaults to value of autocluster
31                                variable CLUSTER.
32
33     --mountpoint=<dir>         The directory where the GPFS filesystem
34                                should be mounted.
35
36 EOF
37     exit 1
38 }
39
40 gpfs_num_nsds="@@GPFS_DEFAULT_NSDS@@"
41 cluster_name="@@CLUSTER@@"
42 mountpoint="@@CLUSTERFS_DEFAULT_MOUNTPOINT@@"
43
44 opts="gpfs-num-nsds:,cluster-name:,mountpoint:"
45 getopt_output=$(getopt -n autocluster -o h -l "$opts" -- "$@")
46 [ $? != 0 ] && usage
47
48 eval set -- "$getopt_output"
49 while true ; do
50     case "$1" in
51         --gpfs-num-nsds) gpfs_num_nsds="$2"  ; shift 2 ;;
52         --cluster-name)  cluster_name="$2"   ; shift 2 ;;
53         --mountpoint)    mountpoint="$2"     ; shift 2 ;;
54         --) shift ; break ;;
55         -h) usage ;;
56         *)  echo "Unknown option \"$1\"" ; usage ;;
57     esac
58 done
59
60 [ -z "$1" ] || usage
61
62 ####################
63
64 domain=$(dnsdomainname)
65 nodes=$(onnode -q all hostname | grep -i $domain | tr 'A-Z\012' 'a-z\040')
66 first="${nodes%% *}"
67 primary="$first"
68 if [ "$first" != "$nodes" ] ; then
69     # More than 1 node...
70     rest="${nodes#* }"
71     secondary="${rest%% *}"
72 else
73     secondary=""
74 fi
75
76 if [ -n "$nsd_servers" ] ; then
77     nodes="${nodes} ${nsd_servers//,/ }"
78
79     # Determine secondary GPFS server.  Is there a 2nd NSD server?  If
80     # not then use node 0 of the CTDB cluster.
81     secondary="${nsd_servers#*,}"
82     secondary="${secondary%%,*}"
83     [ -n "$secondary" -a "$secondary" != "${nsd_servers%%,*}" ] || \
84         secondary="$primary"
85
86     # Primary is just the 1st NSD server.
87     primary="${nsd_servers%%,*}"
88 fi
89
90 nodefile=/tmp/nodes.$$
91 for n in $nodes; do
92     designation="manager"
93     if [ -n "$nsd_servers" ] ; then
94         # This designates the $nsd_servers and $first as quorum nodes.
95         foo="${nsd_servers},"
96         if [ "$n" = "$first" -o "$foo" != "${foo/${n},/}" ] ; then
97             designation="${designation}-quorum"
98         fi
99     else
100         designation="${designation}-quorum"
101     fi
102     echo "$n:${designation}:"
103 done > $nodefile
104
105 echo "Creating cluster"
106 mmcrcluster -N $nodefile -p $primary ${secondary:+-s} $secondary -r /usr/bin/ssh -R /usr/bin/scp -C $cluster_name.$domain
107
108 # GPFS 3.3 needs this... and GPFS 3.2 doesn't have mmchlicense, so
109 # this seems like a good option for now.
110 if type mmchlicense >/dev/null 2>&1 ; then
111     mmchlicense server --accept  -N all
112 fi
113
114 echo
115 echo "Attempting to set adminMode=allToAll"
116 mmchconfig adminMode=allToAll </dev/null  || true
117
118 . $(dirname $0)/mknsd.sh
119
120 echo
121 echo "Generating auth key"
122 mmauth genkey new
123
124 echo
125 echo "Setting GPFS config options"
126 mmchconfig autoload=yes,leaseRecoveryWait=3,maxFilesToCache=20000,failureDetectionTime=10,maxMBpS=500,unmountOnDiskFail=yes,pagepool=64M,allowSambaCaseInsensitiveLookup=no,cipherList=AUTHONLY
127
128 echo "Starting gpfs"
129 mmstartup -a
130
131 echo "Waiting for gpfs to become active"
132 count=0
133 while  mmgetstate -a | tail -n +4 | grep -v " active" > /dev/null; do
134     echo -n "."
135     count=$(($count + 1))
136     if [ $count -gt 60 ] ; then
137         echo "TIMEOUT: gpfs didn't become active"
138         exit 1
139     fi
140     sleep 1
141 done
142 echo
143
144 echo
145 echo "Creating filesystem"
146 mkdir -p "${mountpoint}/automountdir"
147
148 nsdfile2=/tmp/nsd2.$$
149 if [ -n "$gpfs_num_nsds" ] ; then
150     head -n $(($gpfs_num_nsds * 2))
151 else
152     cat
153 fi <$nsdfile >$nsdfile2
154
155 chattr +i "$mountpoint"
156 mmcrfs gpfs0 -F $nsdfile2 -A yes -Q yes -D nfs4 -B 64k -k nfs4 -n 32 -E yes -S no -T "$mountpoint" -i 512
157
158 echo 
159 echo "Mounting filesystem"
160 mmmount gpfs0 -a
161
162 echo "Waiting for gpfs to mount"
163 while ! mount | grep /dev/gpfs0 > /dev/null; do echo -n "."; sleep 1; done
164 echo
165
166 echo "GPFS setup complete"
167
168 #  LocalWords:  DEF