root / trunk / shell / start-compute-node @ 59
Historique | Voir | Annoter | Télécharger (5,21 ko)
1 | 3 | storres | #! /bin/bash |
---|---|---|---|
2 | 3 | storres | # |
3 | 3 | storres | # Start a fresh node (cloned from the compute-node model). |
4 | 3 | storres | # |
5 | 3 | storres | # Get the directory of the script. |
6 | 3 | storres | SCRIPT_PATH=`dirname $0` |
7 | 3 | storres | # Get the script name. |
8 | 3 | storres | SCRIPT_NAME=`basename $0` |
9 | 3 | storres | if [ "x$1" == "x" ] |
10 | 3 | storres | then |
11 | 3 | storres | echo |
12 | 3 | storres | echo Missing parameter. Aborting! |
13 | 3 | storres | echo |
14 | 3 | storres | echo Usage: $SCRIPT_NAME node_number |
15 | 3 | storres | echo |
16 | 3 | storres | exit 1 |
17 | 3 | storres | else |
18 | 3 | storres | echo "node_number: $1" |
19 | 3 | storres | NODE_NUMBER=$(($1)) |
20 | 3 | storres | NODE_NUMBER_STRING=$NODE_NUMBER |
21 | 3 | storres | while [ ${#NODE_NUMBER_STRING} -lt 3 ] |
22 | 3 | storres | do |
23 | 3 | storres | NODE_NUMBER_STRING="0$NODE_NUMBER_STRING" |
24 | 3 | storres | done |
25 | 3 | storres | fi |
26 | 3 | storres | echo $NODE_NUMBER_STRING |
27 | 3 | storres | #exit 0 |
28 | 3 | storres | # Source the common configuration variables. |
29 | 3 | storres | . $SCRIPT_PATH/c-i-a-b.common |
30 | 3 | storres | # |
31 | 3 | storres | # Check that the virtual machine does not already exist. |
32 | 3 | storres | # |
33 | 3 | storres | CURRENT_HOST_NAME=${COMPUTE_NODE_NAME_PREFIX}${NODE_NUMBER_STRING} |
34 | 3 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
35 | 3 | storres | if [ -n "$IS_RUNNING" ] |
36 | 3 | storres | then |
37 | 3 | storres | echo |
38 | 3 | storres | echo The \"$CURRENT_HOST_NAME\" domU already exists. Aborting! |
39 | 3 | storres | echo |
40 | 3 | storres | exit 1 |
41 | 3 | storres | fi |
42 | 3 | storres | |
43 | 3 | storres | # Create the VM system disk (a snapshot of the model disk). |
44 | 3 | storres | COMPUTE_NODE_SYSTEM_DISK="${SYSTEM_DISK_CLONE_PREFIX}${NODE_NUMBER_STRING}${SYSTEM_DISK_CLONE_POSTFIX}" |
45 | 3 | storres | lvcreate -L$SYSTEM_DISK_CLONE_SIZE -s \ |
46 | 3 | storres | -n $COMPUTE_NODE_SYSTEM_DISK \ |
47 | 3 | storres | $SYSTEM_DISK_MASTER |
48 | 3 | storres | # DO NOT CREATE A FILE SYSTEM ON THE SNAPSHOT! |
49 | 3 | storres | # Create the swap volume for the compute node |
50 | 3 | storres | COMPUTE_NODE_SWAP_DISK="${SWAP_DISK_PREFIX}${NODE_NUMBER_STRING}${SWAP_DISK_POSTFIX}" |
51 | 3 | storres | lvcreate -L $SWAP_DISK_SIZE \ |
52 | 3 | storres | -n $COMPUTE_NODE_SWAP_DISK \ |
53 | 3 | storres | $SWAP_DISK_LOGICAL_VOLUME |
54 | 3 | storres | mkswap $SWAP_DISK_LOGICAL_VOLUME/$COMPUTE_NODE_SWAP_DISK |
55 | 3 | storres | # Mount the system disk to copy all the specific files. |
56 | 3 | storres | mount $SWAP_DISK_LOGICAL_VOLUME/$COMPUTE_NODE_SYSTEM_DISK \ |
57 | 3 | storres | $COMPUTE_NODE_DISK_MOUNT_POINT |
58 | 3 | storres | # |
59 | 3 | storres | # Configure the specific files from templates |
60 | 3 | storres | # |
61 | 3 | storres | # /etc/network/interfaces |
62 | 3 | storres | CURRENT_PATH=/etc/network |
63 | 50 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/interfaces \ |
64 | 3 | storres | $COMPUTE_NODE_DISK_MOUNT_POINT/$CURRENT_PATH |
65 | 3 | storres | ADDRESS="$COMPUTE_NODE_STATIC_NETWORK_PREFIX.$NODE_NUMBER" |
66 | 3 | storres | rpl __STATIC_ADDRESS__ $ADDRESS \ |
67 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/interfaces |
68 | 3 | storres | # /etc/hostname |
69 | 3 | storres | CURRENT_PATH=/etc |
70 | 3 | storres | echo $CURRENT_HOST_NAME > "${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/hostname" |
71 | 3 | storres | # /etc/hosts |
72 | 3 | storres | CURRENT_PATH=/etc |
73 | 3 | storres | CURRENT_HOST_IP="${COMPUTE_NODE_STATIC_NETWORK_PREFIX}.${NODE_NUMBER}" |
74 | 50 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/hosts \ |
75 | 3 | storres | $COMPUTE_NODE_DISK_MOUNT_POINT/$CURRENT_PATH |
76 | 3 | storres | rpl __COMPUTE_NODE_IP__ $CURRENT_HOST_IP \ |
77 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
78 | 3 | storres | rpl __COMPUTE_NODE_NAME__ $CURRENT_HOST_NAME \ |
79 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/hosts |
80 | 3 | storres | # /etc/resolv.conf |
81 | 3 | storres | CURRENT_PATH=/etc |
82 | 50 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/resolv.conf \ |
83 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
84 | 3 | storres | rpl __CLUSTER_DOMAIN_NAME__ "${CLUSTER_DOMAIN_NAME}." \ |
85 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
86 | 3 | storres | rpl __FRONT_END_STATIC_ADDRESS__ "${CLUSTER_STATIC_NETWORK_PREFIX}.$FRONT_END_STATIC_NETWORK_POSTFIX" \ |
87 | 3 | storres | ${COMPUTE_NODE_DISK_MOUNT_POINT}${CURRENT_PATH}/resolv.conf |
88 | 3 | storres | # |
89 | 3 | storres | # Get the MAC address |
90 | 3 | storres | # |
91 | 3 | storres | CURRENT_PATH=/etc |
92 | 3 | storres | COMPUTE_NODE_MAC_ADDRESS=\ |
93 | 50 | storres | `awk -F, -v INDEX=$NODE_NUMBER '{if (FNR==INDEX) {print $1}}' $SCRIPT_PATH/${CONST_TEMPLATES_DIR}$CURRENT_PATH/$CONST_DHCP_HOSTS_FILE_BASENAME` |
94 | 3 | storres | # |
95 | 3 | storres | # Create the Xen configuration file from a template |
96 | 3 | storres | # |
97 | 3 | storres | CURRENT_PATH=/etc/xen |
98 | 50 | storres | cp ${CONST_TEMPLATES_DIR}$CURRENT_PATH/compute-node.cfg \ |
99 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
100 | 3 | storres | rpl Template Configuration $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
101 | 3 | storres | rpl "the Xen instance compute-node" "compute-node-$NODE_NUMBER_STRING" \ |
102 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
103 | 3 | storres | rpl __COMPUTE_NODE_KERNEL__ $COMPUTE_NODE_KERNEL \ |
104 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
105 | 3 | storres | rpl __COMPUTE_NODE_RAMDISK__ $COMPUTE_NODE_RAMDISK \ |
106 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
107 | 3 | storres | rpl __COMPUTE_NODE_MEMORY__ $COMPUTE_NODE_MEMORY \ |
108 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
109 | 3 | storres | rpl __COMPUTE_NODE_VCPUS__ $COMPUTE_NODE_VCPUS \ |
110 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
111 | 3 | storres | CPUS_LIST=`sed -n ${NODE_NUMBER},${NODE_NUMBER}p $SCRIPT_PATH/$COMPUTE_NODE_CPUS_FILE` |
112 | 3 | storres | CPUS="" |
113 | 3 | storres | for i in $CPUS_LIST |
114 | 3 | storres | do |
115 | 3 | storres | if [ "x$CPUS" == "x" ] |
116 | 3 | storres | then |
117 | 3 | storres | CPUS=$i |
118 | 3 | storres | else |
119 | 3 | storres | CPUS="$CPUS,$i" |
120 | 3 | storres | fi |
121 | 3 | storres | done |
122 | 3 | storres | rpl __COMPUTE_NODE_CPUS__ $CPUS \ |
123 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
124 | 3 | storres | rpl __COMPUTE_NODE_SYSTEM_DISK__ $SYSTEM_DISK_LOGICAL_VOLUME/$COMPUTE_NODE_SYSTEM_DISK \ |
125 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
126 | 3 | storres | rpl __COMPUTE_NODE_SWAP_DISK__ $SYSTEM_DISK_LOGICAL_VOLUME/$COMPUTE_NODE_SWAP_DISK \ |
127 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
128 | 3 | storres | rpl __COMPUTE_NODE_HOST_NAME__ $CURRENT_HOST_NAME \ |
129 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
130 | 3 | storres | rpl __COMPUTE_NODE_IP__ $ADDRESS \ |
131 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
132 | 3 | storres | rpl __COMPUTE_NODE_MAC__ $COMPUTE_NODE_MAC_ADDRESS \ |
133 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
134 | 3 | storres | rpl __COMPUTE_NODE_BRIDGE__ $COMPUTE_NODE_BRIDGE \ |
135 | 3 | storres | $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
136 | 3 | storres | |
137 | 3 | storres | # |
138 | 3 | storres | # Umount the compute node system disk |
139 | 3 | storres | # |
140 | 3 | storres | umount $COMPUTE_NODE_DISK_MOUNT_POINT |
141 | 3 | storres | # |
142 | 3 | storres | # Start the virtual machine |
143 | 3 | storres | # |
144 | 3 | storres | xm create $SCRIPT_PATH/$CURRENT_HOST_NAME.cfg |
145 | 3 | storres | # |
146 | 3 | storres | # Wait until the virtual machine has started |
147 | 3 | storres | # |
148 | 3 | storres | IS_RUNNING="" |
149 | 3 | storres | while [ -z "$IS_RUNNING" ] |
150 | 3 | storres | do |
151 | 3 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
152 | 3 | storres | sleep 1 |
153 | 3 | storres | done |
154 | 3 | storres | # |
155 | 3 | storres | # Pin the VCPUs to "real" CPUs. |
156 | 3 | storres | # |
157 | 3 | storres | VCPU_NUM=0 |
158 | 3 | storres | for i in $CPUS_LIST |
159 | 3 | storres | do |
160 | 3 | storres | xm vcpu-pin $CURRENT_HOST_NAME $VCPU_NUM $i |
161 | 3 | storres | VCPU_NUM=$((VCPU_NUM + 1)) |
162 | 3 | storres | done |