Statistiques
| Révision :

root / trunk / shell / configuration-start-compute-nodes @ 56

Historique | Voir | Annoter | Télécharger (3,36 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 53 storres
if [ "x$1" == "x" ] ; then
26 53 storres
    echo
27 53 storres
    echo "Missing parameter. Aborting!"
28 53 storres
    echo
29 53 storres
    echo "Usage: $SCRIPT_NAME configuration"
30 53 storres
    echo
31 53 storres
    echo -e "  configuration: one of $CONFIGURATIONS_STRING\b}"
32 53 storres
    echo
33 53 storres
    echo
34 53 storres
    exit 1
35 51 storres
fi
36 51 storres
#
37 51 storres
# Does the configuration exist?
38 51 storres
#
39 51 storres
CONFIGURATION_FOUND=""
40 51 storres
CONFIGURATION=`echo $1 | tr [:upper:] [:lower:]`
41 51 storres
for i in $CONFIGURATIONS ; do
42 51 storres
    CURRENT_CONFIGURATION=`echo $i | tr [:upper:] [:lower:]`
43 51 storres
    if [ $CONFIGURATION == $CURRENT_CONFIGURATION ] ; then
44 51 storres
      CONFIGURATION_FOUND=$i
45 51 storres
    fi
46 51 storres
done
47 51 storres
if [ -z $CONFIGURATION_FOUND ] ; then
48 51 storres
  echo
49 51 storres
  echo
50 51 storres
  echo "The configuration \"$1\" does not exist".
51 51 storres
  echo -e "The configuration must be one of $CONFIGURATIONS_STRING\b}."
52 51 storres
  echo "Aborting!"
53 51 storres
  echo
54 51 storres
  echo
55 51 storres
  exit 1
56 51 storres
else
57 51 storres
  CONFIGURATION=$CONFIGURATION_FOUND
58 51 storres
fi
59 51 storres
#
60 51 storres
# Source the specific variables for the configuration.
61 51 storres
#
62 51 storres
. $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/c-i-a-b.config.common
63 51 storres
#
64 51 storres
# Start the compute-nodes.
65 51 storres
#
66 51 storres
COMPUTE_NODE_INDEX=1
67 51 storres
while [ $COMPUTE_NODE_INDEX -le $COMPUTE_NODE_MAX_INDEX ] ; do
68 51 storres
  #
69 51 storres
  # Convert the number into a three caracters strings.
70 51 storres
  #
71 51 storres
  COMPUTE_NODE_INDEX_STRING=$COMPUTE_NODE_INDEX
72 51 storres
  while [ ${#COMPUTE_NODE_INDEX_STRING} -lt 3 ] ; do
73 51 storres
    COMPUTE_NODE_INDEX_STRING="0$COMPUTE_NODE_INDEX_STRING"
74 51 storres
  done
75 51 storres
  #
76 51 storres
  # Compute the host name.
77 51 storres
  #
78 51 storres
  CURRENT_HOST_NAME=${COMPUTE_NODE_NAME_PREFIX}${COMPUTE_NODE_INDEX_STRING}
79 51 storres
  #
80 51 storres
  # Check if the corresponding VM is already running.
81 51 storres
  #
82 51 storres
  IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME`
83 51 storres
  if [ -n "$IS_RUNNING" ] ; then
84 51 storres
    echo
85 51 storres
    echo The \"$CURRENT_HOST_NAME\" domU already exists.
86 51 storres
    echo
87 51 storres
  fi
88 51 storres
  #
89 51 storres
  # Get the CPU data.
90 51 storres
  #
91 51 storres
  COMPUTE_NODE_CPUS=`sed -n ${COMPUTE_NODE_INDEX},${COMPUTE_NODE_INDEX}p $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/$COMPUTE_NODE_CPUS_FILE`
92 51 storres
  COMPUTE_NODE_VCPUS_NUM=0
93 51 storres
  COMPUTE_NODE_CPUS_LIST=""
94 51 storres
  for i in $COMPUTE_NODE_CPUS ; do
95 51 storres
    if [ -z $COMPUTE_NODE_CPUS_LIST ] ; then
96 51 storres
      COMPUTE_NODE_CPUS_LIST=$i
97 51 storres
    else
98 51 storres
      COMPUTE_NODE_CPUS_LIST="$COMPUTE_NODE_CPUS_LIST,$i"
99 51 storres
    fi
100 51 storres
    COMPUTE_NODE_VCPUS_NUM=$((COMPUTE_NODE_VCPUS_NUM + 1))
101 51 storres
  done
102 51 storres
  #
103 51 storres
  # Check that the configuration file exists.
104 51 storres
  #
105 51 storres
  if [ ! -f $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg ] ; then
106 51 storres
    echo
107 51 storres
    echo
108 51 storres
    echo "No configuration file for \"$CURRENT_HOST_NAME\."
109 51 storres
    echo "Aborting!"
110 51 storres
    echo
111 51 storres
    echo
112 51 storres
    xm list
113 51 storres
    exit 1
114 51 storres
  fi
115 51 storres
  #
116 51 storres
  # Start the virtual machine
117 51 storres
  #
118 51 storres
  xm create $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg
119 51 storres
  #
120 51 storres
  # Wait until the virtual machine has started
121 51 storres
  #
122 51 storres
  IS_RUNNING=""
123 51 storres
  while [ -z "$IS_RUNNING" ]
124 51 storres
    do
125 51 storres
      IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME`
126 51 storres
      sleep 1
127 51 storres
  done # End while
128 51 storres
  #
129 51 storres
  # Pin the VCPUs to "real" CPUs.
130 51 storres
  #
131 51 storres
  VCPU_INDEX=0
132 51 storres
  for i in $COMPUTE_NODE_CPUS_LIST ; do
133 51 storres
    xm vcpu-pin $CURRENT_HOST_NAME $VCPU_INDEX $i
134 51 storres
    VCPU_INDEX=$((VCPU_INDEX + 1))
135 51 storres
  done # End for i
136 51 storres
  COMPUTE_NODE_INDEX=$((COMPUTE_NODE_INDEX + 1))
137 51 storres
done # End main loop.
138 51 storres
#
139 51 storres
exit 0