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