root / trunk / shell / configuration-stop-compute-nodes
Historique | Voir | Annoter | Télécharger (2,58 ko)
| 1 | 53 | storres | #! /bin/bash |
|---|---|---|---|
| 2 | 51 | storres | # |
| 3 | 51 | storres | # ST - 2012-07-03 |
| 4 | 51 | storres | # |
| 5 | 51 | storres | # Start the compute nodes for a configuration. |
| 6 | 51 | storres | # |
| 7 | 51 | storres | # Get the directory of the script. |
| 8 | 51 | storres | SCRIPT_PATH=`dirname $0` |
| 9 | 51 | storres | # Get the script name. |
| 10 | 51 | storres | SCRIPT_NAME=`basename $0` |
| 11 | 51 | storres | # Source the common configuration variables. |
| 12 | 51 | storres | . $SCRIPT_PATH/c-i-a-b.common |
| 13 | 51 | storres | # |
| 14 | 51 | storres | # |
| 15 | 51 | storres | # Get the configurations |
| 16 | 51 | storres | # |
| 17 | 51 | storres | CONFIGURATIONS=`ls $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR` |
| 18 | 51 | storres | CONFIGURATIONS_STRING="{"
|
| 19 | 51 | storres | for i in $CONFIGURATIONS ; do |
| 20 | 51 | storres | CONFIGURATIONS_STRING="$CONFIGURATIONS_STRING$i|" |
| 21 | 51 | storres | done |
| 22 | 51 | storres | # |
| 23 | 51 | storres | # Check command line arguments. |
| 24 | 51 | storres | # |
| 25 | 51 | storres | if [ "x$1" == "x" ] |
| 26 | 51 | storres | then |
| 27 | 53 | storres | echo |
| 28 | 53 | storres | echo "Missing parameter. Aborting!" |
| 29 | 53 | storres | echo |
| 30 | 53 | storres | echo "Usage: $SCRIPT_NAME configuration" |
| 31 | 53 | storres | echo |
| 32 | 53 | storres | echo -e " configuration: one of $CONFIGURATIONS_STRING\b}" |
| 33 | 53 | storres | echo |
| 34 | 53 | storres | echo |
| 35 | 53 | storres | exit 1 |
| 36 | 51 | storres | fi |
| 37 | 51 | storres | # |
| 38 | 51 | storres | # Does the configuration exist? |
| 39 | 51 | storres | # |
| 40 | 51 | storres | CONFIGURATION_FOUND="" |
| 41 | 51 | storres | CONFIGURATION=`echo $1 | tr [:upper:] [:lower:]` |
| 42 | 51 | storres | for i in $CONFIGURATIONS ; do |
| 43 | 51 | storres | CURRENT_CONFIGURATION=`echo $i | tr [:upper:] [:lower:]` |
| 44 | 51 | storres | if [ $CONFIGURATION == $CURRENT_CONFIGURATION ] ; then |
| 45 | 51 | storres | CONFIGURATION_FOUND=$i |
| 46 | 51 | storres | fi |
| 47 | 51 | storres | done |
| 48 | 51 | storres | if [ -z $CONFIGURATION_FOUND ] ; then |
| 49 | 51 | storres | echo |
| 50 | 51 | storres | echo |
| 51 | 51 | storres | echo "The configuration \"$1\" does not exist". |
| 52 | 51 | storres | echo -e "The configuration must be one of $CONFIGURATIONS_STRING\b}." |
| 53 | 51 | storres | echo "Aborting!" |
| 54 | 51 | storres | echo |
| 55 | 51 | storres | echo |
| 56 | 51 | storres | exit 1 |
| 57 | 51 | storres | else |
| 58 | 51 | storres | CONFIGURATION=$CONFIGURATION_FOUND |
| 59 | 51 | storres | fi |
| 60 | 51 | storres | # |
| 61 | 51 | storres | # Source the specific variables for the configuration. |
| 62 | 51 | storres | # |
| 63 | 51 | storres | . $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/c-i-a-b.config.common |
| 64 | 51 | storres | # |
| 65 | 53 | storres | # Stop the compute-nodes. |
| 66 | 51 | storres | # |
| 67 | 51 | storres | COMPUTE_NODE_INDEX=1 |
| 68 | 51 | storres | while [ $COMPUTE_NODE_INDEX -le $COMPUTE_NODE_MAX_INDEX ] ; do |
| 69 | 51 | storres | # |
| 70 | 51 | storres | # Convert the number into a three caracters strings. |
| 71 | 51 | storres | # |
| 72 | 51 | storres | COMPUTE_NODE_INDEX_STRING=$COMPUTE_NODE_INDEX |
| 73 | 51 | storres | while [ ${#COMPUTE_NODE_INDEX_STRING} -lt 3 ] ; do
|
| 74 | 51 | storres | COMPUTE_NODE_INDEX_STRING="0$COMPUTE_NODE_INDEX_STRING" |
| 75 | 51 | storres | done |
| 76 | 51 | storres | # |
| 77 | 51 | storres | # Compute the host name. |
| 78 | 51 | storres | # |
| 79 | 51 | storres | CURRENT_HOST_NAME=${COMPUTE_NODE_NAME_PREFIX}${COMPUTE_NODE_INDEX_STRING}
|
| 80 | 51 | storres | # |
| 81 | 51 | storres | # Check if the corresponding VM is already running. |
| 82 | 51 | storres | # |
| 83 | 51 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
| 84 | 53 | storres | if [ ! -z "$IS_RUNNING" ] ; then |
| 85 | 53 | storres | echo "Stopping $CURRENT_HOST_NAME..." |
| 86 | 53 | storres | # |
| 87 | 53 | storres | # Stop the virtual machine |
| 88 | 53 | storres | # |
| 89 | 53 | storres | xm shutdown $CURRENT_HOST_NAME |
| 90 | 53 | storres | if [ $? -ne 0 ] ; then |
| 91 | 53 | storres | ciab_abort_message "Can't stop $CURRENT_HOST_NAME" 1 |
| 92 | 51 | storres | fi |
| 93 | 53 | storres | # |
| 94 | 53 | storres | # Wait until the virtual machine has stopped. |
| 95 | 53 | storres | # |
| 96 | 60 | storres | IS_RUNNING="dummy" |
| 97 | 53 | storres | while [ ! -z "$IS_RUNNING" ] |
| 98 | 53 | storres | do |
| 99 | 53 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
| 100 | 53 | storres | sleep 1 |
| 101 | 53 | storres | done # End while |
| 102 | 53 | storres | else |
| 103 | 53 | storres | echo "$CURRENT_HOST_NAME is already stopped." |
| 104 | 53 | storres | fi # End if IS_RUNNING. |
| 105 | 51 | storres | COMPUTE_NODE_INDEX=$((COMPUTE_NODE_INDEX + 1)) |
| 106 | 51 | storres | done # End main loop. |
| 107 | 51 | storres | # |
| 108 | 51 | storres | exit 0 |