root / trunk / shell / configuration-delete-compute-nodes @ 57
Historique | Voir | Annoter | Télécharger (3,34 ko)
1 | 57 | storres | #! /bin/bash |
---|---|---|---|
2 | 51 | storres | # |
3 | 51 | storres | # ST - 2012-07-04 |
4 | 51 | storres | # |
5 | 51 | storres | # Delete 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 | # Get the configurations |
15 | 51 | storres | # |
16 | 51 | storres | CONFIGURATIONS=`ls $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR` |
17 | 51 | storres | CONFIGURATIONS_STRING="{" |
18 | 51 | storres | for i in $CONFIGURATIONS ; do |
19 | 51 | storres | CONFIGURATIONS_STRING="$CONFIGURATIONS_STRING$i|" |
20 | 51 | storres | done |
21 | 51 | storres | # |
22 | 51 | storres | # Check command line arguments. |
23 | 51 | storres | # |
24 | 51 | storres | if [ "x$1" == "x" ] |
25 | 51 | storres | then |
26 | 51 | storres | echo |
27 | 51 | storres | echo "Missing parameter. Aborting!" |
28 | 51 | storres | echo |
29 | 51 | storres | echo "Usage: $SCRIPT_NAME configuration" |
30 | 51 | storres | echo |
31 | 51 | storres | echo -e " configuration: one of $CONFIGURATIONS_STRING\b}" |
32 | 51 | storres | exit 1 |
33 | 51 | storres | fi |
34 | 51 | storres | # |
35 | 51 | storres | # Does the configuration exist? |
36 | 51 | storres | # |
37 | 51 | storres | CONFIGURATION_FOUND="" |
38 | 51 | storres | CONFIGURATION=`echo $1 | tr [:upper:] [:lower:]` |
39 | 51 | storres | for i in $CONFIGURATIONS ; do |
40 | 51 | storres | CURRENT_CONFIGURATION=`echo $i | tr [:upper:] [:lower:]` |
41 | 51 | storres | if [ $CONFIGURATION == $CURRENT_CONFIGURATION ] ; then |
42 | 51 | storres | CONFIGURATION_FOUND=$i |
43 | 51 | storres | fi |
44 | 51 | storres | done |
45 | 51 | storres | if [ -z $CONFIGURATION_FOUND ] ; then |
46 | 51 | storres | echo |
47 | 51 | storres | echo |
48 | 51 | storres | echo "The configuration \"$1\" does not exist". |
49 | 51 | storres | echo -e "The configuration must be one of $CONFIGURATIONS_STRING\b}." |
50 | 51 | storres | echo "Aborting!" |
51 | 51 | storres | echo |
52 | 51 | storres | echo |
53 | 51 | storres | exit 1 |
54 | 51 | storres | else |
55 | 51 | storres | CONFIGURATION=$CONFIGURATION_FOUND |
56 | 51 | storres | fi |
57 | 51 | storres | # |
58 | 51 | storres | # Source the specific variables for the configuration. |
59 | 51 | storres | # |
60 | 51 | storres | . $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/c-i-a-b.config.common |
61 | 51 | storres | # |
62 | 51 | storres | # Delete the compute nodes. |
63 | 51 | storres | # |
64 | 51 | storres | COMPUTE_NODE_INDEX=1 |
65 | 51 | storres | while [ $COMPUTE_NODE_INDEX -le $COMPUTE_NODE_MAX_INDEX ] ; do |
66 | 51 | storres | # |
67 | 51 | storres | # Compute the host name. |
68 | 51 | storres | # |
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 | 53 | storres | echo "Deleting $CURRENT_HOST_NAME..." |
82 | 53 | storres | # |
83 | 51 | storres | # If the compute node is running, stop it. |
84 | 51 | storres | # |
85 | 51 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
86 | 51 | storres | if [ ! -z "$IS_RUNNING" ] ; then |
87 | 51 | storres | xm shutdown $CURRENT_HOST_NAME |
88 | 51 | storres | # |
89 | 51 | storres | # And wait until it has sopped. |
90 | 51 | storres | # |
91 | 51 | storres | IS_RUNNING="" |
92 | 51 | storres | while [ -z "$IS_RUNNING" ] ; do |
93 | 51 | storres | IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME` |
94 | 51 | storres | sleep 1 |
95 | 51 | storres | done # End while |
96 | 53 | storres | sleep 1 # Extra delay after VM is stopped. |
97 | 51 | storres | fi # End compute node is running. |
98 | 51 | storres | # |
99 | 51 | storres | # If necessary, delete the VM system disk. |
100 | 51 | storres | # |
101 | 51 | storres | COMPUTE_NODE_SYSTEM_DISK_DEVICE="${COMPUTE_NODE_MODEL_SYSTEM_VOLUME_GROUP_DEVICE}/${CURRENT_HOST_NAME}-${CONST_SYSTEM_DISK_POSTFIX}-clone" |
102 | 51 | storres | if [ -e $COMPUTE_NODE_SYSTEM_DISK_DEVICE ] ; then |
103 | 51 | storres | lvremove -f $COMPUTE_NODE_SYSTEM_DISK_DEVICE |
104 | 51 | storres | if [ $? -ne 0 ] ; then |
105 | 51 | storres | ciab_abort_message "Could not remove system disk for $CURRENT_HOST_NAME" 1 |
106 | 51 | storres | fi |
107 | 51 | storres | fi |
108 | 51 | storres | # |
109 | 51 | storres | # If necessary, remove the swap volume for the compute node. |
110 | 51 | storres | # |
111 | 51 | storres | COMPUTE_NODE_SWAP_DISK_DEVICE="COMPUTE_NODE_SWAP_DISK_VOLUME_GROUP_DEVICE/${CURRENT_HOST_NAME}-${CONST_SWAP_DISK_POSTFIX}" |
112 | 51 | storres | if [ -e $COMPUTE_NODE_SWAP_DISK_DEVICE ] ; then |
113 | 51 | storres | lvremove -f $COMPUTE_NODE_SWAP_DISK_DEVICE |
114 | 51 | storres | if [ $? -ne 0 ] ; then |
115 | 51 | storres | ciab_abort_message "Could not remove swap disk for $CURRENT_HOST_NAME" 1 |
116 | 51 | storres | fi |
117 | 51 | storres | fi |
118 | 51 | storres | # |
119 | 51 | storres | # Remove the Xen configuration file. |
120 | 51 | storres | # |
121 | 51 | storres | CURRENT_PATH=/etc/xen |
122 | 51 | storres | rm -f $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg |
123 | 51 | storres | # |
124 | 51 | storres | COMPUTE_NODE_INDEX=$((COMPUTE_NODE_INDEX + 1)) |
125 | 51 | storres | done |
126 | 51 | storres | exit 0 |