root / trunk / shell / configuration-create-compute-nodes @ 58
Historique | Voir | Annoter | Télécharger (9,76 ko)
1 | 53 | storres | #! /bin/bash |
---|---|---|---|
2 | 51 | storres | # |
3 | 51 | storres | # ST - 2012-07-04 |
4 | 51 | storres | # |
5 | 51 | storres | # Create the compute nodes for a configuration. |
6 | 51 | storres | # Prerequisite: the compute node model must have been created. |
7 | 51 | storres | # |
8 | 51 | storres | # Get the directory of the script. |
9 | 51 | storres | SCRIPT_PATH=`dirname $0` |
10 | 51 | storres | # Get the script name. |
11 | 51 | storres | SCRIPT_NAME=`basename $0` |
12 | 51 | storres | # Source the common configuration variables. |
13 | 51 | storres | . $SCRIPT_PATH/c-i-a-b.common |
14 | 51 | storres | # |
15 | 51 | storres | # Get the configurations |
16 | 51 | storres | # |
17 | 51 | storres | CONFIGURATIONS=`ls $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR` |
18 | 51 | storres | CONFIGURATIONS_STRING="{" |
19 | 51 | storres | for i in $CONFIGURATIONS ; do |
20 | 51 | storres | CONFIGURATIONS_STRING="$CONFIGURATIONS_STRING$i|" |
21 | 51 | storres | done |
22 | 51 | storres | # |
23 | 51 | storres | # Check command line arguments. |
24 | 51 | storres | # |
25 | 51 | storres | if [ "x$1" == "x" ] |
26 | 51 | storres | then |
27 | 51 | storres | echo |
28 | 51 | storres | echo "Missing parameter. Aborting!" |
29 | 51 | storres | echo |
30 | 51 | storres | echo "Usage: $SCRIPT_NAME configuration" |
31 | 51 | storres | echo |
32 | 51 | storres | echo -e " configuration: one of $CONFIGURATIONS_STRING\b}" |
33 | 51 | storres | exit 1 |
34 | 51 | storres | fi |
35 | 51 | storres | # |
36 | 51 | storres | # Does the configuration exist? |
37 | 51 | storres | # |
38 | 51 | storres | CONFIGURATION_FOUND="" |
39 | 51 | storres | CONFIGURATION=`echo $1 | tr [:upper:] [:lower:]` |
40 | 51 | storres | for i in $CONFIGURATIONS ; do |
41 | 51 | storres | CURRENT_CONFIGURATION=`echo $i | tr [:upper:] [:lower:]` |
42 | 51 | storres | if [ $CONFIGURATION == $CURRENT_CONFIGURATION ] ; then |
43 | 51 | storres | CONFIGURATION_FOUND=$i |
44 | 51 | storres | fi |
45 | 51 | storres | done |
46 | 51 | storres | if [ -z $CONFIGURATION_FOUND ] ; then |
47 | 51 | storres | echo |
48 | 51 | storres | echo |
49 | 51 | storres | echo "The configuration \"$1\" does not exist". |
50 | 51 | storres | echo -e "The configuration must be one of $CONFIGURATIONS_STRING\b}." |
51 | 51 | storres | echo "Aborting!" |
52 | 51 | storres | echo |
53 | 51 | storres | echo |
54 | 51 | storres | exit 1 |
55 | 51 | storres | else |
56 | 51 | storres | CONFIGURATION=$CONFIGURATION_FOUND |
57 | 51 | storres | fi |
58 | 51 | storres | # |
59 | 51 | storres | # Source the specific variables for the configuration. |
60 | 51 | storres | # |
61 | 51 | storres | . $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/c-i-a-b.config.common |
62 | 51 | storres | # |
63 | 51 | storres | # Create the compute nodes. |
64 | 51 | storres | # |
65 | 51 | storres | COMPUTE_NODE_INDEX=1 |
66 | 51 | storres | while [ $COMPUTE_NODE_INDEX -le $COMPUTE_NODE_MAX_INDEX ] ; do |
67 | 51 | storres | # |
68 | 51 | storres | # Compute the host name. |
69 | 51 | storres | # |
70 | 51 | storres | # |
71 | 51 | storres | # Convert the number into a three caracters strings. |
72 | 51 | storres | # |
73 | 51 | storres | COMPUTE_NODE_INDEX_STRING=$COMPUTE_NODE_INDEX |
74 | 51 | storres | while [ ${#COMPUTE_NODE_INDEX_STRING} -lt 3 ] ; do |
75 | 51 | storres | COMPUTE_NODE_INDEX_STRING="0$COMPUTE_NODE_INDEX_STRING" |
76 | 51 | storres | done |
77 | 51 | storres | # |
78 | 51 | storres | # Compute the host name. |
79 | 51 | storres | # |
80 | 51 | storres | CURRENT_HOST_NAME=${COMPUTE_NODE_NAME_PREFIX}${COMPUTE_NODE_INDEX_STRING} |
81 | 51 | storres | # |
82 | 53 | storres | echo "Creating $CURRENT_HOST_NAME..." |
83 | 53 | storres | # |
84 | 51 | storres | # Get the compute node MAC address on the cluster. |
85 | 51 | storres | # |
86 | 51 | storres | CURRENT_PATH=/etc |
87 | 53 | storres | COMPUTE_NODE_CLUSTER_MAC_ADDRESS=`awk -F, -v INDEX=$COMPUTE_NODE_INDEX '{if (FNR==INDEX) {print $1}}' $SCRIPT_PATH/${CONST_TEMPLATES_DIR}$CURRENT_PATH/$CONST_DHCP_HOSTS_FILE_BASENAME` |
88 | 51 | storres | # |
89 | 51 | storres | # Create the VM system disk (a snapshot of the model disk). |
90 | 51 | storres | # |
91 | 51 | storres | COMPUTE_NODE_SYSTEM_DISK="${CURRENT_HOST_NAME}-${CONST_SYSTEM_DISK_POSTFIX}-clone" |
92 | 51 | storres | COMPUTE_NODE_LOGICAL_VOLUME="${COMPUTE_NODE_MODEL_SYSTEM_VOLUME_GROUP_DEVICE}/${COMPUTE_NODE_MODEL_CLUSTER_HOST_NAME}-$CONST_SYSTEM_DISK_POSTFIX" |
93 | 51 | storres | lvcreate -L$COMPUTE_NODE_SYSTEM_DISK_CLONE_SIZE -s \ |
94 | 51 | storres | -n $COMPUTE_NODE_SYSTEM_DISK \ |
95 | 51 | storres | $COMPUTE_NODE_LOGICAL_VOLUME > /dev/null 2>&1 |
96 | 51 | storres | if [ $? -ne 0 ] ; then |
97 | 51 | storres | ciab_abort_message "Could not create system disk for $CURRENT_HOST_NAME" 1 |
98 | 51 | storres | fi |
99 | 51 | storres | # |
100 | 51 | storres | # DO NOT CREATE A FILE SYSTEM ON THE SNAPSHOT! |
101 | 51 | storres | # |
102 | 51 | storres | # If necessary, create the swap volume for the compute node. |
103 | 51 | storres | if [ $COMPUTE_NODE_SWAP_DISK_SIZE != $CONST_NULL_DISK_SIZE ] ; then |
104 | 51 | storres | COMPUTE_NODE_SWAP_DISK="${CURRENT_HOST_NAME}-${CONST_SWAP_DISK_POSTFIX}" |
105 | 51 | storres | lvcreate -L $COMPUTE_NODE_SWAP_DISK_SIZE \ |
106 | 51 | storres | -n $COMPUTE_NODE_SWAP_DISK \ |
107 | 51 | storres | $COMPUTE_NODE_SWAP_DISK_VOLUME_GROUP |
108 | 51 | storres | if [ $? -ne 0 ] ; then |
109 | 51 | storres | ciab_abort_message "Could not create swap disk for $CURRENT_HOST_NAME" 1 |
110 | 51 | storres | fi |
111 | 51 | storres | mkswap $COMPUTE_NODE_SWAP_DISK_VOLUME_GROUP_DEVICE/$COMPUTE_NODE_SWAP_DISK |
112 | 51 | storres | if [ $? -ne 0 ] ; then |
113 | 51 | storres | ciab_abort_message "Could not initialize swap disk for $CURRENT_HOST_NAME" 1 |
114 | 51 | storres | fi |
115 | 51 | storres | fi |
116 | 51 | storres | # |
117 | 51 | storres | # Get the CPU data. |
118 | 51 | storres | # |
119 | 51 | storres | COMPUTE_NODE_CPUS=`sed -n ${COMPUTE_NODE_INDEX},${COMPUTE_NODE_INDEX}p $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/$COMPUTE_NODE_CPUS_FILE` |
120 | 51 | storres | COMPUTE_NODE_VCPUS_NUM=0 |
121 | 51 | storres | COMPUTE_NODE_CPUS_LIST="" |
122 | 51 | storres | for i in $COMPUTE_NODE_CPUS ; do |
123 | 51 | storres | if [ -z $COMPUTE_NODE_CPUS_LIST ] ; then |
124 | 51 | storres | COMPUTE_NODE_CPUS_LIST=$i |
125 | 51 | storres | else |
126 | 51 | storres | COMPUTE_NODE_CPUS_LIST="$COMPUTE_NODE_CPUS_LIST,$i" |
127 | 51 | storres | fi |
128 | 51 | storres | COMPUTE_NODE_VCPUS_NUM=$((COMPUTE_NODE_VCPUS_NUM + 1)) |
129 | 51 | storres | done # for i |
130 | 51 | storres | # |
131 | 51 | storres | # Create the Xen configuration file from a template |
132 | 51 | storres | # |
133 | 51 | storres | CURRENT_PATH=/etc/xen |
134 | 51 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/$CONST_COMPUTE_NODE_XEN_TEMPLATE_NAME \ |
135 | 51 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
136 | 53 | storres | rpl -q Template Configuration $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
137 | 51 | storres | rpl -q __COMPUTE_NODE_KERNEL__ "$COMPUTE_NODE_KERNEL" \ |
138 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
139 | 51 | storres | rpl -q __COMPUTE_NODE_RAMDISK__ "$COMPUTE_NODE_RAMDISK" \ |
140 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
141 | 51 | storres | rpl -q __COMPUTE_NODE_VCPUS_NUM__ "$COMPUTE_NODE_VCPUS_NUM" \ |
142 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
143 | 51 | storres | rpl -q __COMPUTE_NODE_CPUS__ "$COMPUTE_NODE_CPUS_LIST" \ |
144 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
145 | 51 | storres | # Memory |
146 | 51 | storres | rpl -q __COMPUTE_NODE_MEMORY__ "$COMPUTE_NODE_MEMORY" \ |
147 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
148 | 51 | storres | # Root device |
149 | 51 | storres | rpl -q __XEN_SYSTEM_DISK_ROOT_DEVICE_STANZA__ "$CONST_XEN_SYSTEM_DISK_ROOT_DEVICE_STANZA" \ |
150 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
151 | 51 | storres | # |
152 | 51 | storres | # System disk stuff |
153 | 51 | storres | # |
154 | 51 | storres | COMPUTE_NODE_SYSTEM_DISK_STANZA="'phy:${COMPUTE_NODE_MODEL_SYSTEM_VOLUME_GROUP_DEVICE}/${COMPUTE_NODE_SYSTEM_DISK},$COMPUTE_NODE_SYSTEM_VIRTUAL_VOLUME,w'" |
155 | 51 | storres | rpl -q __COMPUTE_NODE_SYSTEM_DISK_STANZA__ "$COMPUTE_NODE_SYSTEM_DISK_STANZA" \ |
156 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
157 | 51 | storres | # |
158 | 51 | storres | # No home disk stuff: home is network mounted. |
159 | 51 | storres | # |
160 | 51 | storres | # Swap disk stuff. |
161 | 51 | storres | if [ "x$COMPUTE_NODE_SWAP_DISK_SIZE" != "x$CONST_NULL_DISK_SIZE" ] ; then |
162 | 51 | storres | COMPUTE_NODE_SWAP_DISK_STANZA="'phy:${COMPUTE_NODE_SWAP_DISK_VOLUME_GROUP_DEVICE}/${COMPUTE_NODE_SWAP_DISK},$COMPUTE_NODE_SWAP_VIRTUAL_VOLUME,w'" |
163 | 51 | storres | rpl -q __COMPUTE_NODE_SWAP_DISK_STANZA__ "$COMPUTE_NODE_SWAP_DISK_STANZA" \ |
164 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
165 | 51 | storres | # Comment out the noswap stanza. |
166 | 51 | storres | rpl -q __COMPUTE_NODE_NOSWAP__ "#$CLUSTER_NOSWAP" \ |
167 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
168 | 51 | storres | else # No swap |
169 | 51 | storres | rpl -q __COMPUTE_NODE_SWAP_DISK_STANZA__ "" \ |
170 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
171 | 51 | storres | rpl -q __COMPUTE_NODE_NOSWAP__ "$CLUSTER_NOSWAP" \ |
172 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
173 | 51 | storres | fi |
174 | 51 | storres | # |
175 | 51 | storres | rpl -q __COMPUTE_NODE_HOST_NAME__ "$CURRENT_HOST_NAME" \ |
176 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
177 | 51 | storres | # Vif stuff. |
178 | 53 | storres | |
179 | 53 | storres | COMPUTE_NODE_CLUSTER_STATIC_IP=`awk -F, -v INDEX=$COMPUTE_NODE_INDEX '{if (FNR==INDEX) {print $3}}' $SCRIPT_PATH/${CONST_TEMPLATES_DIR}/etc/$CONST_DHCP_HOSTS_FILE_BASENAME` |
180 | 51 | storres | VIF_STANZA=$CONST_XEN_VIF_STANZA_PREFIX |
181 | 51 | storres | INTERNAL_MAC="${CONST_XEN_MAC_PREFIX}${COMPUTE_NODE_CLUSTER_MAC_ADDRESS}" |
182 | 51 | storres | INTERNAL_BRIDGE="${CONST_XEN_BRIDGE_PREFIX}${CLUSTER_BRIDGE_NAME}" |
183 | 51 | storres | INTERNAL_IP="${CONST_XEN_IP_PREFIX}${COMPUTE_NODE_CLUSTER_STATIC_IP}" |
184 | 51 | storres | if [ $CLUSTER_INTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ; then |
185 | 51 | storres | rpl -q __XEN_DHCP_STANZA__ "$CONST_XEN_DHCP_STANZA" \ |
186 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
187 | 51 | storres | VIF_STANZA=${VIF_STANZA}${INTERNAL_IP}","${INTERNAL_MAC}","${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
188 | 51 | storres | else |
189 | 51 | storres | # Comment out the DHCP_STANZA. |
190 | 51 | storres | rpl -q __XEN_DHCP_STANZA__ "#$CONST_XEN_DHCP_STANZA" \ |
191 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
192 | 51 | storres | VIF_STANZA=${VIF_STANZA}${INTERNAL_IP}","${INTERNAL_MAC},${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
193 | 51 | storres | fi |
194 | 51 | storres | # In any case, write the VIF_STANZA |
195 | 51 | storres | rpl -q __VIF_STANZA__ "$VIF_STANZA" \ |
196 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
197 | 51 | storres | # Console stuff as extra parameter |
198 | 51 | storres | rpl -q __EXTRA_STANZA__ "$CONST_XEN_EXTRA_STANZA" \ |
199 | 53 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg > /dev/null 2>&1 |
200 | 51 | storres | # End creation of Xen configuration file. |
201 | 51 | storres | # |
202 | 51 | storres | # Complete installation |
203 | 51 | storres | # |
204 | 51 | storres | # Mount the file system to append/modify configuration files |
205 | 51 | storres | # |
206 | 51 | storres | if [ ! -d $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT ] ; then |
207 | 51 | storres | mkdir $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT |
208 | 51 | storres | fi |
209 | 51 | storres | mount $COMPUTE_NODE_MODEL_SYSTEM_VOLUME_GROUP_DEVICE/$COMPUTE_NODE_SYSTEM_DISK \ |
210 | 51 | storres | $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT |
211 | 51 | storres | if [ $? -ne 0 ] ; then |
212 | 51 | storres | echo |
213 | 51 | storres | echo "Could not mount the compute node file system. Aborting!" |
214 | 51 | storres | echo |
215 | 51 | storres | exit 1 |
216 | 51 | storres | fi |
217 | 51 | storres | # |
218 | 51 | storres | # Generate or configure the specific files from templates |
219 | 51 | storres | # |
220 | 51 | storres | # Create the /etc directory, if necessary |
221 | 51 | storres | if [ ! -d $COMPUTE_NODE_MODEL_FILE_SYSTEM_MOUNT_POINT/etc ] ; then |
222 | 51 | storres | mkdir $COMPUTE_NODE_MODEL_FILE_SYSTEM_MOUNT_POINT/etc |
223 | 51 | storres | fi |
224 | 51 | storres | # /etc/network/interfaces |
225 | 51 | storres | # The first interface is DHCP configured. |
226 | 51 | storres | # No '/' between $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT and $CURRENT_PATH |
227 | 51 | storres | CURRENT_PATH=/etc/network |
228 | 51 | storres | if [ ! -d ${COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH} ] ; then |
229 | 51 | storres | mkdir ${COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH} |
230 | 51 | storres | fi |
231 | 51 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/$COMPUTE_NODE_INTERFACES_TEMPLATE \ |
232 | 51 | storres | $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT$CURRENT_PATH/interfaces |
233 | 51 | storres | # Static address on the cluster interface. |
234 | 51 | storres | # The DHCP case should be delt with. It involves a template overhaul. |
235 | 51 | storres | rpl -q __STATIC_ADDRESS__ "$COMPUTE_NODE_CLUSTER_STATIC_IP" \ |
236 | 53 | storres | ${COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces > /dev/null 2>&1 |
237 | 51 | storres | rpl -q __STATIC_NETMASK__ "$CLUSTER_STATIC_NETMASK" \ |
238 | 53 | storres | ${COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces > /dev/null 2>&1 |
239 | 51 | storres | |
240 | 51 | storres | # /etc/hostname |
241 | 51 | storres | CURRENT_PATH=/etc |
242 | 51 | storres | echo $CURRENT_HOST_NAME > "${COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/hostname" |
243 | 51 | storres | # |
244 | 51 | storres | # /etc/hosts. We use the clone. |
245 | 51 | storres | # |
246 | 51 | storres | # /etc/resolv.conf. We use the clone. |
247 | 51 | storres | # |
248 | 51 | storres | # /etc/fstab. We use the clone. |
249 | 51 | storres | # |
250 | 51 | storres | # /etc/inittab stuff. We use the clone. |
251 | 51 | storres | # |
252 | 51 | storres | # Umount the compute node model system disk |
253 | 51 | storres | # |
254 | 51 | storres | umount $COMPUTE_NODE_FILE_SYSTEM_MOUNT_POINT |
255 | 51 | storres | # |
256 | 51 | storres | COMPUTE_NODE_INDEX=$((COMPUTE_NODE_INDEX + 1)) |
257 | 51 | storres | done |
258 | 51 | storres | exit 0 |