root / trunk / shell / create-start-front-end @ 26
Historique | Voir | Annoter | Télécharger (8,86 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 | 25 | storres | # /etc/network/interfaces |
137 | 25 | storres | # The first interface is DHCP configured. |
138 | 25 | storres | CURRENT_PATH=/etc/network |
139 | 25 | storres | cp templates$CURRENT_PATH/$FRONT_END_INTERFACES_TEMPLATE \ |
140 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
141 | 25 | storres | if [ $CLUSTER_EXTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ;then |
142 | 25 | storres | ETH0_STANZA="iface eth0 inet dhcp" |
143 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
144 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
145 | 25 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "" |
146 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
147 | 25 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "" |
148 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
149 | 25 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "" |
150 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
151 | 25 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "" |
152 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
153 | 25 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "" |
154 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
155 | 25 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "" |
156 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
157 | 25 | storres | else |
158 | 25 | storres | ETH0_STANZA="iface eth0 inet static" |
159 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
160 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
161 | 25 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "$FRONT_END_CLUSTER_STATIC_IP" |
162 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
163 | 25 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETMASK" |
164 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
165 | 25 | storres | echo y | rpl __ETH0_STATIC_NETWORK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETWORK" |
166 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
167 | 25 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_GATEWAY" |
168 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
169 | 25 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_BROADCAST" |
170 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
171 | 25 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_NAMESERVERS" |
172 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
173 | 25 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_SEARCH" |
174 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
175 | 25 | storres | fi |
176 | 25 | storres | ADDRESS="$CLUSTER_STATIC_NETWORK_PREFIX.$FRONT_END_STATIC_NETWORK_POSTFIX" |
177 | 25 | storres | rpl __ETH1_STATIC_ADDRESS__ $ADDRESS \ |
178 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH/interfaces |
179 | 25 | storres | # /etc/hostname |
180 | 25 | storres | CURRENT_PATH=/etc |
181 | 25 | storres | echo $CURRENT_HOST_NAME > "${FRONT_END_DISK_MOUNT_POINT}${CURRENT_PATH}/hostname" |
182 | 25 | storres | # /etc/hosts |
183 | 25 | storres | CURRENT_PATH=/etc |
184 | 25 | storres | CURRENT_HOST_IP="${CLUSTER_STATIC_NETWORK_PREFIX}.${FRONT_END_STATIC_NETWORK_POSTFIX}" |
185 | 25 | storres | cp templates$CURRENT_PATH/hosts \ |
186 | 25 | storres | $FRONT_END_SYSTEM_DISK_MOUNT_POINT/$CURRENT_PATH |
187 | 25 | storres | rpl __COMPUTE_NODE_IP__ $CURRENT_HOST_IP \ |
188 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
189 | 25 | storres | rpl __COMPUTE_NODE_NAME__ $CURRENT_HOST_NAME \ |
190 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
191 | 25 | storres | # /etc/resolv.conf |
192 | 25 | storres | CURRENT_PATH=/etc |
193 | 25 | storres | cp $TEMPLATES_DIR$CURRENT_PATH/resolv.conf \ |
194 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
195 | 25 | storres | rpl __CLUSTER_DOMAIN_NAME__ "${CLUSTER_DOMAIN_NAME}." \ |
196 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
197 | 25 | storres | rpl __FRONT_END_STATIC_ADDRESS__ "${CLUSTER_STATIC_NETWORK_PREFIX}.$FRONT_END_STATIC_NETWORK_POSTFIX" \ |
198 | 25 | storres | ${FRONT_END_SYSTEM_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
199 | 23 | storres | exit 0 |
200 | 23 | storres | # |
201 | 16 | storres | # Umount the compute node system disk |
202 | 16 | storres | # |
203 | 23 | storres | umount $FRONT_END_SYSTEM_DISK_MOUNT_POINT |
204 | 16 | storres | # |
205 | 16 | storres | # Start the virtual machine |
206 | 16 | storres | # |
207 | 24 | storres | xm create $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
208 | 16 | storres | # |
209 | 16 | storres | # Wait until the virtual machine has started |
210 | 16 | storres | # |
211 | 16 | storres | IS_RUNNING="" |
212 | 16 | storres | while [ -z "$IS_RUNNING" ] |
213 | 16 | storres | do |
214 | 16 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
215 | 16 | storres | sleep 1 |
216 | 16 | storres | done |
217 | 16 | storres | # |
218 | 16 | storres | # Pin the VCPUs to "real" CPUs. |
219 | 16 | storres | # |
220 | 16 | storres | VCPU_NUM=0 |
221 | 16 | storres | for i in $CPUS_LIST |
222 | 16 | storres | do |
223 | 16 | storres | xm vcpu-pin $CURRENT_HOST_NAME $VCPU_NUM $i |
224 | 16 | storres | VCPU_NUM=$((VCPU_NUM + 1)) |
225 | 17 | storres | done |
226 | 20 | storres | |
227 | 20 | storres | exit 0 |