root / trunk / shell / create-start-front-end @ 27
Historique | Voir | Annoter | Télécharger (9,4 ko)
1 | 17 | storres | #! /bin/bash -x |
---|---|---|---|
2 | 16 | storres | # |
3 | 17 | storres | # ST - 2012-03-09 |
4 | 17 | storres | # |
5 | 16 | storres | # Create and start the front end. |
6 | 16 | storres | # |
7 | 16 | storres | # Get the directory of the script. |
8 | 16 | storres | SCRIPT_PATH=`dirname $0` |
9 | 16 | storres | # Get the script name. |
10 | 16 | storres | SCRIPT_NAME=`basename $0` |
11 | 16 | storres | # Source the common configuration variables. |
12 | 16 | storres | . $SCRIPT_PATH/c-i-a-b.common |
13 | 16 | storres | # |
14 | 16 | storres | # Check that the front-end virtual machine does not already exist. |
15 | 16 | storres | # |
16 | 20 | storres | CURRENT_HOST_NAME=$FRONT_END_HOST_NAME |
17 | 16 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
18 | 16 | storres | if [ -n "$IS_RUNNING" ] |
19 | 16 | storres | then |
20 | 16 | storres | echo |
21 | 16 | storres | echo The \"$CURRENT_HOST_NAME\" domU already exists. Aborting! |
22 | 16 | storres | echo |
23 | 16 | storres | exit 1 |
24 | 16 | storres | fi |
25 | 16 | storres | |
26 | 23 | storres | # Create the front-end system disk. |
27 | 17 | storres | lvcreate -L$FRONT_END_SYSTEM_DISK_SIZE \ |
28 | 16 | storres | -n $FRONT_END_SYSTEM_DISK \ |
29 | 17 | storres | $FRONT_END_SYSTEM_VOLUME_GROUP |
30 | 23 | storres | # Create a File System on the front-end system disk. |
31 | 16 | storres | mkfs -t $FRONT_END_SYSTEM_DISK_FILE_SYSTEM \ |
32 | 17 | storres | $FRONT_END_SYSTEM_VOLUME_GROUP_DEVICE/$FRONT_END_SYSTEM_DISK |
33 | 16 | storres | # If necessary, create the swap volume for the front end. |
34 | 16 | storres | if [ $FRONT_END_SWAP_DISK_SIZE != $CONST_NULL_DISK_SIZE ]; then |
35 | 16 | storres | lvcreate -L $FRONT_END_SWAP_DISK_SIZE \ |
36 | 16 | storres | -n $FRONT_END_SWAP_DISK \ |
37 | 17 | storres | $FRONT_END_SWAP_VOLUME_GROUP |
38 | 17 | storres | mkswap $FRONT_END_SWAP_VOLUME_GROUP_DEVICE/$FRONT_END_SWAP_DISK |
39 | 16 | storres | fi |
40 | 23 | storres | # Create the VM home disk. |
41 | 23 | storres | lvcreate -L$FRONT_END_HOME_DISK_SIZE \ |
42 | 23 | storres | -n $FRONT_END_HOME_DISK \ |
43 | 23 | storres | $FRONT_END_HOME_VOLUME_GROUP |
44 | 23 | storres | # Create a File System on the front-end system disk. |
45 | 23 | storres | mkfs -t $FRONT_END_HOME_DISK_FILE_SYSTEM \ |
46 | 23 | storres | $FRONT_END_HOME_VOLUME_GROUP_DEVICE/$FRONT_END_HOME_DISK |
47 | 16 | storres | # Mount the system disk to copy all the specific files. |
48 | 16 | storres | if [ ! -d $FRONT_END_SYSTEM_DISK_MOUNT_POINT ]; then |
49 | 16 | storres | mkdir $FRONT_END_SYSTEM_DISK_MOUNT_POINT |
50 | 16 | storres | fi |
51 | 17 | storres | mount $FRONT_END_SYSTEM_VOLUME_GROUP_DEVICE/$FRONT_END_SYSTEM_DISK \ |
52 | 16 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT |
53 | 16 | storres | # |
54 | 22 | storres | # Get the cluster MAC address |
55 | 16 | storres | # |
56 | 16 | storres | CURRENT_PATH=/etc |
57 | 21 | storres | FRONT_END_CLUSTER_MAC_ADDRESS=\ |
58 | 20 | storres | `awk -F, -v INDEX=$FRONT_END_STATIC_NETWORK_POSTFIX '{if (FNR==INDEX) {print $1}}' $SCRIPT_PATH/$TEMPLATES_DIR$CURRENT_PATH/$DHCP_HOSTSFILE_BASENAME` |
59 | 16 | storres | # |
60 | 16 | storres | # Create the Xen configuration file from a template |
61 | 16 | storres | # |
62 | 16 | storres | CURRENT_PATH=/etc/xen |
63 | 23 | storres | cp templates$CURRENT_PATH/$CONST_FRONT_END_TEMPLATE_NAME \ |
64 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
65 | 23 | storres | rpl Template Configuration $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
66 | 21 | storres | rpl __FRONT_END_KERNEL__ $COMPUTE_NODE_KERNEL \ |
67 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
68 | 23 | storres | rpl __FRONT_END_RAMDISK__ $FRONT_END_RAMDISK \ |
69 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
70 | 23 | storres | rpl __FRONT_END_VCPUS_NUM__ $FRONT_END_VCPUS_NUM \ |
71 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
72 | 21 | storres | CPUS_LIST=$FRONT_END_CPUS_LIST |
73 | 16 | storres | CPUS="" |
74 | 16 | storres | for i in $CPUS_LIST |
75 | 16 | storres | do |
76 | 16 | storres | if [ "x$CPUS" == "x" ] |
77 | 16 | storres | then |
78 | 16 | storres | CPUS=$i |
79 | 16 | storres | else |
80 | 16 | storres | CPUS="$CPUS,$i" |
81 | 16 | storres | fi |
82 | 16 | storres | done |
83 | 21 | storres | rpl __FRONT_END_CPUS__ $CPUS \ |
84 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
85 | 24 | storres | # Memory |
86 | 24 | storres | rpl __FRONT_END_MEMORY__ $FRONT_END_MEMORY \ |
87 | 24 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
88 | 24 | storres | # Root device |
89 | 24 | storres | rpl __XEN_SYSTEM_DISK_ROOT_DEVICE__ "$CONST_XEN_SYSTEM_DISK_ROOT_DEVICE" \ |
90 | 24 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
91 | 24 | storres | # |
92 | 21 | storres | rpl __FRONT_END_SYSTEM_DISK__ $FRONT_END_SYSTEM_VOLUME_GROUP_DEVICE/$FRONT_END_SYSTEM_DISK \ |
93 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
94 | 23 | storres | rpl __FRONT_END_HOME_DISK__ $FRONT_END_HOME_VOLUME_GROUP_DEVICE/$FRONT_END_HOME_DISK \ |
95 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
96 | 25 | storres | # Swap disk stuff. |
97 | 21 | storres | if [ "x$FRONT_END_SWAP_DISK_SIZE" != "x$CONST_NULL_DISK_SIZE" ] ; then |
98 | 21 | storres | FRONT_END_SWAP_DISK_STANZA="'phy:$FRONT_END_SWAP_VOLUME_GROUP_DEVICE/${FRONT_END_SWAP_DISK},xvda3,w'," |
99 | 21 | storres | rpl __FRONT_END_SWAP_DISK__ $FRONT_END_SWAP_DISK_STANZA \ |
100 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
101 | 23 | storres | # Comment out the noswap stanza. |
102 | 23 | storres | rpl __FRONT_END_NOSWAP__ "#$CLUSTER_NOSWAP" \ |
103 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
104 | 21 | storres | else |
105 | 23 | storres | echo y | rpl -f __FRONT_END_SWAP_DISK__ "" \ |
106 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
107 | 21 | storres | rpl __FRONT_END_NOSWAP__ $CLUSTER_NOSWAP \ |
108 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
109 | 21 | storres | fi |
110 | 25 | storres | # |
111 | 21 | storres | rpl __FRONT_END_HOST_NAME__ $CURRENT_HOST_NAME \ |
112 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
113 | 25 | storres | # Vif stuff. |
114 | 23 | storres | VIF_STANZA=$CONST_XEN_VIF_STANZA_PREFIX |
115 | 23 | storres | EXTERNAL_MAC="${CONST_XEN_MAC_PREFIX}${FRONT_END_EXTERNAL_MAC_ADDRESS}" |
116 | 23 | storres | INTERNAL_MAC="${CONST_XEN_MAC_PREFIX}${FRONT_END_CLUSTER_MAC_ADDRESS}" |
117 | 24 | storres | INTERNAL_BRIDGE="${CONST_XEN_BRIDGE_PREFIX}${CLUSTER_BRIDGE_NAME}" |
118 | 24 | storres | INTERNAL_IP="${CONST_XEN_IP_PREFIX}${FRONT_END_CLUSTER_STATIC_IP}" |
119 | 22 | storres | if [ $CLUSTER_EXTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ;then |
120 | 23 | storres | rpl __XEN_DHCP_STANZA__ "$CONST_XEN_DHCP_STANZA" \ |
121 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
122 | 24 | storres | VIF_STANZA=${VIF_STANZA}${EXTERNAL_MAC}"','"${INTERNAL_IP}","${INTERNAL_MAC}","${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
123 | 22 | storres | else |
124 | 23 | storres | # Comment out the DHCP_STANZA. |
125 | 23 | storres | rpl __XEN_DHCP_STANZA__ "#$CONST_XEN_DHCP_STANZA" \ |
126 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
127 | 24 | storres | VIF_STANZA=${VIF_STANZA}${EXTERNAL_IP}","${EXTERNAL_MAC}",'"${INTERNAL_IP}","${INTERNAL_MAC},${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
128 | 23 | storres | fi |
129 | 23 | storres | # In any case, write the VIF_STANZA |
130 | 24 | storres | rpl __VIF_STANZA__ "$VIF_STANZA" \ |
131 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
132 | 16 | storres | # |
133 | 25 | storres | # |
134 | 25 | storres | # Configure the specific files from templates |
135 | 25 | storres | # |
136 | 27 | storres | # Create the /etc directory, if necessary |
137 | 27 | storres | if [ ! -d $FRONT_END_SYSTEM_DISK_MOUNT_POINT/etc ] ; then |
138 | 27 | storres | mkdir $FRONT_END_SYSTEM_DISK_MOUNT_POINT/etc |
139 | 27 | storres | fi |
140 | 25 | storres | # /etc/network/interfaces |
141 | 25 | storres | # The first interface is DHCP configured. |
142 | 27 | storres | # No '/' between $FRONT_END_SYSTEM_DISK_MOUNT_POINT and $CURRENT_PATH |
143 | 25 | storres | CURRENT_PATH=/etc/network |
144 | 27 | storres | if [ ! -d ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH} ] ; then |
145 | 27 | storres | mkdir ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH} |
146 | 27 | storres | fi |
147 | 25 | storres | cp templates$CURRENT_PATH/$FRONT_END_INTERFACES_TEMPLATE \ |
148 | 27 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT$CURRENT_PATH/interfaces |
149 | 27 | storres | if [ $CLUSTER_EXTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ; then |
150 | 25 | storres | ETH0_STANZA="iface eth0 inet dhcp" |
151 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
152 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
153 | 27 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "" \ |
154 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
155 | 27 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "" \ |
156 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
157 | 27 | storres | echo y | rpl __ETH0_STATIC_NETWORK__ "" \ |
158 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
159 | 27 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "" \ |
160 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
161 | 27 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "" \ |
162 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
163 | 27 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "" \ |
164 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
165 | 27 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "" \ |
166 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
167 | 25 | storres | else |
168 | 25 | storres | ETH0_STANZA="iface eth0 inet static" |
169 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
170 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
171 | 27 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "$FRONT_END_CLUSTER_STATIC_IP" \ |
172 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
173 | 27 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETMASK" \ |
174 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
175 | 27 | storres | echo y | rpl __ETH0_STATIC_NETWORK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETWORK" \ |
176 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
177 | 27 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_GATEWAY" \ |
178 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
179 | 27 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_BROADCAST" \ |
180 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
181 | 27 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_NAMESERVERS" \ |
182 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
183 | 27 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_SEARCH" \ |
184 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
185 | 25 | storres | fi |
186 | 25 | storres | ADDRESS="$CLUSTER_STATIC_NETWORK_PREFIX.$FRONT_END_STATIC_NETWORK_POSTFIX" |
187 | 25 | storres | rpl __ETH1_STATIC_ADDRESS__ $ADDRESS \ |
188 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
189 | 25 | storres | # /etc/hostname |
190 | 25 | storres | CURRENT_PATH=/etc |
191 | 25 | storres | echo $CURRENT_HOST_NAME > "${FRONT_END_DISK_MOUNT_POINT}${CURRENT_PATH}/hostname" |
192 | 25 | storres | # /etc/hosts |
193 | 25 | storres | CURRENT_PATH=/etc |
194 | 25 | storres | CURRENT_HOST_IP="${CLUSTER_STATIC_NETWORK_PREFIX}.${FRONT_END_STATIC_NETWORK_POSTFIX}" |
195 | 25 | storres | cp templates$CURRENT_PATH/hosts \ |
196 | 27 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH} |
197 | 25 | storres | rpl __COMPUTE_NODE_IP__ $CURRENT_HOST_IP \ |
198 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
199 | 25 | storres | rpl __COMPUTE_NODE_NAME__ $CURRENT_HOST_NAME \ |
200 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
201 | 25 | storres | # /etc/resolv.conf |
202 | 25 | storres | CURRENT_PATH=/etc |
203 | 25 | storres | cp $TEMPLATES_DIR$CURRENT_PATH/resolv.conf \ |
204 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
205 | 25 | storres | rpl __CLUSTER_DOMAIN_NAME__ "${CLUSTER_DOMAIN_NAME}." \ |
206 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
207 | 25 | storres | rpl __FRONT_END_STATIC_ADDRESS__ "${CLUSTER_STATIC_NETWORK_PREFIX}.$FRONT_END_STATIC_NETWORK_POSTFIX" \ |
208 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
209 | 23 | storres | exit 0 |
210 | 23 | storres | # |
211 | 16 | storres | # Umount the compute node system disk |
212 | 16 | storres | # |
213 | 23 | storres | umount $FRONT_END_SYSTEM_DISK_MOUNT_POINT |
214 | 16 | storres | # |
215 | 16 | storres | # Start the virtual machine |
216 | 16 | storres | # |
217 | 24 | storres | xm create $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
218 | 16 | storres | # |
219 | 16 | storres | # Wait until the virtual machine has started |
220 | 16 | storres | # |
221 | 16 | storres | IS_RUNNING="" |
222 | 16 | storres | while [ -z "$IS_RUNNING" ] |
223 | 16 | storres | do |
224 | 16 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
225 | 16 | storres | sleep 1 |
226 | 16 | storres | done |
227 | 16 | storres | # |
228 | 16 | storres | # Pin the VCPUs to "real" CPUs. |
229 | 16 | storres | # |
230 | 16 | storres | VCPU_NUM=0 |
231 | 16 | storres | for i in $CPUS_LIST |
232 | 16 | storres | do |
233 | 16 | storres | xm vcpu-pin $CURRENT_HOST_NAME $VCPU_NUM $i |
234 | 16 | storres | VCPU_NUM=$((VCPU_NUM + 1)) |
235 | 17 | storres | done |
236 | 20 | storres | |
237 | 20 | storres | exit 0 |