root / trunk / shell / create-start-front-end @ 29
Historique | Voir | Annoter | Télécharger (9,5 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 | 29 | 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 | 29 | storres | # Mount the system disk to install the system. |
48 | 29 | storres | if [ ! -d $FRONT_END_FILE_SYSTEM_MOUNT_POINT ]; then |
49 | 29 | storres | mkdir $FRONT_END_FILE_SYSTEM_MOUNT_POINT |
50 | 16 | storres | fi |
51 | 17 | storres | mount $FRONT_END_SYSTEM_VOLUME_GROUP_DEVICE/$FRONT_END_SYSTEM_DISK \ |
52 | 29 | storres | $FRONT_END_FILE_SYSTEM_MOUNT_POINT |
53 | 29 | storres | # Create the directory for the homes |
54 | 29 | storres | if [ ! -d "$FRONT_END_FILE_SYSTEM_MOUNT_POINT/home" ]; then |
55 | 29 | storres | mkdir "$FRONT_END_FILE_SYSTEM_MOUNT_POINT/home" |
56 | 29 | storres | fi |
57 | 29 | storres | mount $FRONT_END_HOME_VOLUME_GROUP_DEVICE/$FRONT_END_HOME_DISK \ |
58 | 29 | storres | "$FRONT_END_FILE_SYSTEM_MOUNT_POINT/home" |
59 | 29 | storres | |
60 | 16 | storres | # |
61 | 22 | storres | # Get the cluster MAC address |
62 | 16 | storres | # |
63 | 16 | storres | CURRENT_PATH=/etc |
64 | 21 | storres | FRONT_END_CLUSTER_MAC_ADDRESS=\ |
65 | 29 | storres | `awk -F, -v INDEX=$FRONT_END_STATIC_NETWORK_POSTFIX '{if (FNR==INDEX) {print $1}}' $SCRIPT_PATH/$TEMPLATES_DIR$CURRENT_PATH/$CONST_DHCP_HOSTS_FILE_BASENAME` |
66 | 16 | storres | # |
67 | 16 | storres | # Create the Xen configuration file from a template |
68 | 16 | storres | # |
69 | 16 | storres | CURRENT_PATH=/etc/xen |
70 | 23 | storres | cp templates$CURRENT_PATH/$CONST_FRONT_END_TEMPLATE_NAME \ |
71 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
72 | 23 | storres | rpl Template Configuration $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
73 | 21 | storres | rpl __FRONT_END_KERNEL__ $COMPUTE_NODE_KERNEL \ |
74 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
75 | 23 | storres | rpl __FRONT_END_RAMDISK__ $FRONT_END_RAMDISK \ |
76 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
77 | 23 | storres | rpl __FRONT_END_VCPUS_NUM__ $FRONT_END_VCPUS_NUM \ |
78 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
79 | 21 | storres | CPUS_LIST=$FRONT_END_CPUS_LIST |
80 | 16 | storres | CPUS="" |
81 | 16 | storres | for i in $CPUS_LIST |
82 | 16 | storres | do |
83 | 16 | storres | if [ "x$CPUS" == "x" ] |
84 | 16 | storres | then |
85 | 16 | storres | CPUS=$i |
86 | 16 | storres | else |
87 | 16 | storres | CPUS="$CPUS,$i" |
88 | 16 | storres | fi |
89 | 16 | storres | done |
90 | 21 | storres | rpl __FRONT_END_CPUS__ $CPUS \ |
91 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
92 | 24 | storres | # Memory |
93 | 24 | storres | rpl __FRONT_END_MEMORY__ $FRONT_END_MEMORY \ |
94 | 24 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
95 | 24 | storres | # Root device |
96 | 24 | storres | rpl __XEN_SYSTEM_DISK_ROOT_DEVICE__ "$CONST_XEN_SYSTEM_DISK_ROOT_DEVICE" \ |
97 | 24 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
98 | 24 | storres | # |
99 | 21 | storres | rpl __FRONT_END_SYSTEM_DISK__ $FRONT_END_SYSTEM_VOLUME_GROUP_DEVICE/$FRONT_END_SYSTEM_DISK \ |
100 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
101 | 23 | storres | rpl __FRONT_END_HOME_DISK__ $FRONT_END_HOME_VOLUME_GROUP_DEVICE/$FRONT_END_HOME_DISK \ |
102 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
103 | 25 | storres | # Swap disk stuff. |
104 | 21 | storres | if [ "x$FRONT_END_SWAP_DISK_SIZE" != "x$CONST_NULL_DISK_SIZE" ] ; then |
105 | 21 | storres | FRONT_END_SWAP_DISK_STANZA="'phy:$FRONT_END_SWAP_VOLUME_GROUP_DEVICE/${FRONT_END_SWAP_DISK},xvda3,w'," |
106 | 21 | storres | rpl __FRONT_END_SWAP_DISK__ $FRONT_END_SWAP_DISK_STANZA \ |
107 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
108 | 23 | storres | # Comment out the noswap stanza. |
109 | 23 | storres | rpl __FRONT_END_NOSWAP__ "#$CLUSTER_NOSWAP" \ |
110 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
111 | 21 | storres | else |
112 | 23 | storres | echo y | rpl -f __FRONT_END_SWAP_DISK__ "" \ |
113 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
114 | 21 | storres | rpl __FRONT_END_NOSWAP__ $CLUSTER_NOSWAP \ |
115 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
116 | 21 | storres | fi |
117 | 25 | storres | # |
118 | 21 | storres | rpl __FRONT_END_HOST_NAME__ $CURRENT_HOST_NAME \ |
119 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
120 | 25 | storres | # Vif stuff. |
121 | 23 | storres | VIF_STANZA=$CONST_XEN_VIF_STANZA_PREFIX |
122 | 23 | storres | EXTERNAL_MAC="${CONST_XEN_MAC_PREFIX}${FRONT_END_EXTERNAL_MAC_ADDRESS}" |
123 | 23 | storres | INTERNAL_MAC="${CONST_XEN_MAC_PREFIX}${FRONT_END_CLUSTER_MAC_ADDRESS}" |
124 | 24 | storres | INTERNAL_BRIDGE="${CONST_XEN_BRIDGE_PREFIX}${CLUSTER_BRIDGE_NAME}" |
125 | 24 | storres | INTERNAL_IP="${CONST_XEN_IP_PREFIX}${FRONT_END_CLUSTER_STATIC_IP}" |
126 | 22 | storres | if [ $CLUSTER_EXTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ;then |
127 | 23 | storres | rpl __XEN_DHCP_STANZA__ "$CONST_XEN_DHCP_STANZA" \ |
128 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
129 | 24 | storres | VIF_STANZA=${VIF_STANZA}${EXTERNAL_MAC}"','"${INTERNAL_IP}","${INTERNAL_MAC}","${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
130 | 22 | storres | else |
131 | 23 | storres | # Comment out the DHCP_STANZA. |
132 | 23 | storres | rpl __XEN_DHCP_STANZA__ "#$CONST_XEN_DHCP_STANZA" \ |
133 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
134 | 24 | storres | VIF_STANZA=${VIF_STANZA}${EXTERNAL_IP}","${EXTERNAL_MAC}",'"${INTERNAL_IP}","${INTERNAL_MAC},${INTERNAL_BRIDGE}${CONST_XEN_VIF_STANZA_POSTFIX} |
135 | 23 | storres | fi |
136 | 23 | storres | # In any case, write the VIF_STANZA |
137 | 24 | storres | rpl __VIF_STANZA__ "$VIF_STANZA" \ |
138 | 23 | storres | $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
139 | 16 | storres | # |
140 | 29 | storres | # Install the system. |
141 | 29 | storres | # |
142 | 29 | storres | echo deboostrap --arch `uname -m` stable $FRONT_END_FILE_SYSTEM_MOUNT_POINT |
143 | 29 | storres | exit 0 |
144 | 25 | storres | # |
145 | 29 | storres | # |
146 | 25 | storres | # Configure the specific files from templates |
147 | 25 | storres | # |
148 | 27 | storres | # Create the /etc directory, if necessary |
149 | 29 | storres | if [ ! -d $FRONT_END_FILE_SYSTEM_MOUNT_POINT/etc ] ; then |
150 | 29 | storres | mkdir $FRONT_END_FILE_SYSTEM_MOUNT_POINT/etc |
151 | 27 | storres | fi |
152 | 25 | storres | # /etc/network/interfaces |
153 | 25 | storres | # The first interface is DHCP configured. |
154 | 29 | storres | # No '/' between $FRONT_END_FILE_SYSTEM_MOUNT_POINT and $CURRENT_PATH |
155 | 25 | storres | CURRENT_PATH=/etc/network |
156 | 29 | storres | if [ ! -d ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH} ] ; then |
157 | 29 | storres | mkdir ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH} |
158 | 27 | storres | fi |
159 | 25 | storres | cp templates$CURRENT_PATH/$FRONT_END_INTERFACES_TEMPLATE \ |
160 | 29 | storres | $FRONT_END_FILE_SYSTEM_MOUNT_POINT$CURRENT_PATH/interfaces |
161 | 27 | storres | if [ $CLUSTER_EXTERNAL_ADDRESSES_BY_DHCP -eq 1 ] ; then |
162 | 25 | storres | ETH0_STANZA="iface eth0 inet dhcp" |
163 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
164 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
165 | 27 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "" \ |
166 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
167 | 27 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "" \ |
168 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
169 | 27 | storres | echo y | rpl __ETH0_STATIC_NETWORK__ "" \ |
170 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
171 | 27 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "" \ |
172 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
173 | 27 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "" \ |
174 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
175 | 27 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "" \ |
176 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
177 | 27 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "" \ |
178 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
179 | 25 | storres | else |
180 | 25 | storres | ETH0_STANZA="iface eth0 inet static" |
181 | 25 | storres | rpl __ETH0_STATIC_OR_DHCP__ "$ETH0_STANZA" \ |
182 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
183 | 27 | storres | echo y | rpl __ETH0_STATIC_ADDRESS__ "$FRONT_END_CLUSTER_STATIC_IP" \ |
184 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
185 | 27 | storres | echo y | rpl __ETH0_STATIC_NETMASK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETMASK" \ |
186 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
187 | 27 | storres | echo y | rpl __ETH0_STATIC_NETWORK__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_NETWORK" \ |
188 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
189 | 27 | storres | echo y | rpl __ETH0_STATIC_GATEWAY__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_GATEWAY" \ |
190 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
191 | 27 | storres | echo y | rpl __ETH0_STATIC_BROADCAST__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_BROADCAST" \ |
192 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
193 | 27 | storres | echo y | rpl __ETH0_STATIC_NAMESERVERS__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_NAMESERVERS" \ |
194 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
195 | 27 | storres | echo y | rpl __ETH0_STATIC_DNS_SEARCH__ "$FRONT_END_EXTERNAL_INTERFACE_STATIC_DNS_SEARCH" \ |
196 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
197 | 25 | storres | fi |
198 | 25 | storres | ADDRESS="$CLUSTER_STATIC_NETWORK_PREFIX.$FRONT_END_STATIC_NETWORK_POSTFIX" |
199 | 25 | storres | rpl __ETH1_STATIC_ADDRESS__ $ADDRESS \ |
200 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/interfaces |
201 | 25 | storres | # /etc/hostname |
202 | 25 | storres | CURRENT_PATH=/etc |
203 | 25 | storres | echo $CURRENT_HOST_NAME > "${FRONT_END_DISK_MOUNT_POINT}${CURRENT_PATH}/hostname" |
204 | 29 | storres | # /etc/hosts. Script generated. |
205 | 25 | storres | CURRENT_PATH=/etc |
206 | 29 | storres | $SCRIPT_PATH/generate-hosts-file \ |
207 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/hosts |
208 | 25 | storres | # /etc/resolv.conf |
209 | 25 | storres | CURRENT_PATH=/etc |
210 | 25 | storres | cp $TEMPLATES_DIR$CURRENT_PATH/resolv.conf \ |
211 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
212 | 25 | storres | rpl __CLUSTER_DOMAIN_NAME__ "${CLUSTER_DOMAIN_NAME}." \ |
213 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
214 | 29 | storres | rpl __FRONT_END_STATIC_ADDRESS__ "${CLUSTER_STATIC_NETWORK_PREFIX}.${CONST_FRONT_END_CLUSTER_STATIC_NETWORK_POSTFIX}" \ |
215 | 29 | storres | ${FRONT_END_FILE_SYSTEM_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
216 | 23 | storres | # |
217 | 16 | storres | # Umount the compute node system disk |
218 | 16 | storres | # |
219 | 29 | storres | umount $FRONT_END_FILE_SYSTEM_MOUNT_POINT |
220 | 16 | storres | # |
221 | 16 | storres | # Start the virtual machine |
222 | 16 | storres | # |
223 | 24 | storres | xm create $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
224 | 16 | storres | # |
225 | 16 | storres | # Wait until the virtual machine has started |
226 | 16 | storres | # |
227 | 16 | storres | IS_RUNNING="" |
228 | 16 | storres | while [ -z "$IS_RUNNING" ] |
229 | 16 | storres | do |
230 | 16 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
231 | 16 | storres | sleep 1 |
232 | 16 | storres | done |
233 | 16 | storres | # |
234 | 16 | storres | # Pin the VCPUs to "real" CPUs. |
235 | 16 | storres | # |
236 | 16 | storres | VCPU_NUM=0 |
237 | 16 | storres | for i in $CPUS_LIST |
238 | 16 | storres | do |
239 | 16 | storres | xm vcpu-pin $CURRENT_HOST_NAME $VCPU_NUM $i |
240 | 16 | storres | VCPU_NUM=$((VCPU_NUM + 1)) |
241 | 17 | storres | done |
242 | 20 | storres | |
243 | 20 | storres | exit 0 |