source: client/shared/scripts/cloneRemoteFromMaster @ a012113

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since a012113 was 4976431, checked in by irina <irinagomez@…>, 11 years ago

#653 cloneRemoteFromMaster: se incluye configureOsCustom -> postconfiguracion personalizada.

git-svn-id: https://opengnsys.es/svn/branches/version1.0@4363 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 13.2 KB
Line 
1#!/bin/bash
2
3#/**
4#         cloneremoteFromMaster
5#@brief   Restaura una particion o imagen sobre las particiones de equipos cliente remotos
6#@param 1 str_origen admite dirección IP del equipo Master.
7#@param 2 str_origen  admite int_disk    str_REPO|str_CACHE
8#@param 3 str_origen  admite int partorigen   stre_imagen
9#@param 4 str_sesion multicast|unicast
10#@param $5 int_disco_destino
11#@param $6 init_particion_destino
12#@param $7 str_tool_clone
13#@param $8 str_tool_compresor
14#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 1 1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
15#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 REPO /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
16#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 CACHE /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
17#@return 
18#@exception OG_ERR_FORMAT     formato incorrecto.
19#@exception $OG_ERR_IMGSIZEPARTITION=30   #Imagen demasiado pequeña para ser clonada
20#@exception OG_ERR_REDUCEFS=17     #error al reducir sistema de archivos.
21#@exception OG_ERR_EXTENDFS=18     #errror al expandir el sistema de archivos.
22#@exception OG_ERR_UCASTSYNTAXT=50  # Error en la generación de sintaxis de transferenica unicast
23#@exception OG_ERR_UCASTSENDPARTITION=51  # Error en envio UNICAST de una particion
24#@exception OG_ERR_UCASTSENDFILE=52  # Error en envio UNICAST de un fichero
25#@exception OG_ERR_UCASTRECEIVERPARTITION=53  #Error en la recepcion UNICAST de una particion
26#@exception OG_ERR_UCASTRECEIVERFILE=54  #Error en la recepcion UNICAST de un fichero
27#@exception OG_ERR_MCASTSYNTAXT=55 # Error en la generacion de sintaxis de transferenica Multicast.
28#@exception OG_ERR_MCASTSENDFILE=56  # Error en envio MULTICAST de un fichero
29#@exception OG_ERR_MCASTRECEIVERFILE=57  #Error en la recepcion MULTICAST de un fichero
30#@exception OG_ERR_MCASTSENDPARTITION=58  # Error en envio MULTICAST de una particion
31#@exception OG_ERR_MCASTRECEIVERPARTITION=59  # Error en la recepcion MULTICAST de una particion
32#@exception OG_ERR_PROTOCOLJOINMASTER=60 # Error en la conexion de una sesion UNICAST|MULTICAST con el MASTER
33#@note   
34#@todo:
35#@version 0.9.1 - integración con OpenGnsys
36#@author  Antonio J. Doblas Viso. Universidad de Malaga.
37#@date   2009/03/17
38#@version 0.9.2 - adaptacion a OpenGnsys
39#@author  Antonio J. Doblas Viso. Universidad de Malaga.
40#@date    2010/07/27
41#@version 0.1.0 - gestion unicast
42#@author  Antonio J. Doblas Viso. Universidad de Malaga.
43#@date    2011/01/26
44#@version 1.0 - control de errores para el ogAdmServer
45#@author  Antonio J. Doblas Viso. Universidad de Malaga.
46#@date    2011/04/24
47#@version 1.0 - Uso de parted para controlar tamaño particion destino. Requiere Formateo FS previo -parted usa FS para el tamanyo".
48#@author  Antonio J. Doblas Viso. Universidad de Malaga.
49#@date    2011/04/24
50#@version 1.0.1 - Se elimina la operación de reducir la particion.
51#@author  Antonio J. Doblas Viso. Universidad de Malaga.
52#@date    2011/05/16
53#@version 1.0.3 - se integra con httpd-log.
54#@version 1.0.3 - Habilita el uso de la variable OGWINREDUCE=TRUE|TRUE para reducir el sistema de archivos a enviar
55#@author  Antonio J. Doblas Viso. Universidad de Malaga.
56#@date    2011/12/22
57#*/ ##
58
59#test 1. cliente sin particiones.    Detectado  TODO: crear estrucutras de particiones
60#test 2. cliente con particion mas pequeña. Detectado.
61#test 3. cleinte con particion destinio no formateado.  Detectado.
62#test 4. cliente con particion destino ocupado por el usuario pwd .  FALLO.
63#test 5. master sin origen particion.
64#test 6. master sin origen fichero.
65
66#Carga del configurador del engine
67[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
68
69
70trap "pkill faucet; exit 1" 0 1 2 3 6 9 14 15
71
72TIME1=$SECONDS
73PROG="$(basename $0)"
74if [ $# -lt 1 -o "$1" == "help" ]; then
75        echo "cloneRemoteFromMaster ipmaster disk init [MULTICAST|UNICAST] session disk part tool comp"
76        exit 1
77fi
78
79if [  $# -lt 6  ]; then
80    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ipMaster SOURCE_disco SOURCE_particion [MULTICAT|UNICAST] SESSION TARGER_disck TARGET_partition"
81    exit $?
82fi
83
84# Obtener información de los parámetros de entrada.
85HOSTIP=`ogGetIpAddress`
86if [ -z "$HOSTIP" ]
87then
88        source /tmp/net-eth*
89        HOSTIP=`ogGetIpAddress`
90fi
91MASTERIP="$1"
92PROTOCOL="$4"
93case "${PROTOCOL^^}" in
94        MULTICAST)
95                SESSIONMCASTSERVER=$5
96                SESSIONMCASTCLIENT=`echo $5 | awk -F: '{print $1}'`
97        ;;
98        UNICAST)
99                SESSIONUCASTSERVER=$5
100                SESSIONUCASTCLIENT=`echo $5 | awk -F: '{print $1}'`:$MASTERIP
101        ;;
102        *)
103                exit $(ogRaiseError $OG_ERR_FORMAT "Protocolo $PROTOCOL no soportado en esta operacion"; echo $?)
104;;
105esac
106# contenedor destino (disco particion)
107DISKTARGET="$6"
108PARTTARGET="$7"
109#herramienta de compresión.
110TOOLCLONE="$8"
111COMPRESOR="$9"
112
113pkill faucet
114
115# Preparando Instrucción según sea Master o Client
116case $MASTERIP in
117        $HOSTIP)
118                echo "[1] Equipo Master preparando el origen de los datos a enviar"
119                ogGetPath $2 $3.img &>/dev/null; RC=$?;
120                ogDiskToDev $2 $3 &>/dev/null; RETVAL=$?;
121
122                if [ "$RC" == "0" ]; then
123                        IMG=$(ogGetPath $2 $3.img); MODEMASTER=SENDFILE
124                elif [ "$RETVAL" == "0" ]; then
125                        DISKSOURCE=$2; PARTSOURCE=$3; MODEMASTER=SENDPARTITION
126                else
127                        ogRaiseError $OG_ERR_NOTFOUND "$2 $3"; exit $?
128                fi
129                echo $MODEMASTER
130                # Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}                                   
131                case "$MODEMASTER" in
132                        SENDPARTITION)
133                                ogEcho log session "[5] Master en modo $MODEMASTER: informacion inicial a los clientes-slaves"
134                                if ps aux | grep -v grep | grep "faucet 4000"
135                                then
136                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 118"; exit $?     
137                                else
138                                        faucet 4000 --out echo "WORKING" &     
139                                fi                             
140                                ogEcho log session "[10]: Desmontando DISK:$DISKSOURCE PARTITION:$PARTSOURCE"
141                                ogUnmount $2 $3 ||  exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar $2 $3  l124"; echo $?)
142                                #Obtener tamaño de la partición.
143                                SIZE=$(ogGetPartitionSize $2 $3)  || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar tamaño partcion $2 $3  l127"; echo $?)
144                               
145                                if [ "$OGWINREDUCE" == "TRUE" ]
146                                then
147                                        ogEcho log session "[15]: Calculando la reduccion del sistema de archivos DISK:$DISKSOURCE PARTITION:$PARTSOURCE SIZE:$SIZE"
148                                        ogReduceFs $2 $3 || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al reducir el FS $2 $3  l129"; echo $?)
149                                fi
150                                       
151                                REDSIZE=$(ogGetFsSize $2 $3) || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar el nuevo FS $2 $3  l130"; echo $?)     
152                                TIMEAUX=$[SECONDS-TIME1]
153                                ogEcho log session "[20]: Preparada para enviar el sistema de archivos: Tamaño datos: $REDSIZE  origne: $DISKSOURCE $PARTSOURCE"
154                                ogEcho log session "      tiempo de reducción del sistema de archivos: $[TIMEAUX/60]m $[TIMEAUX%60]s"
155                               
156                                #if [ $REDSIZE -lt $SIZE ]; then
157                        #               echo "[24] Redimensionar partición a $REDSIZE KB."
158                        #               ogSetPartitionSize $2 $3 $REDSIZE
159                                #fi
160
161                                ogEcho log session "[25] Master en Modo $MODEMASTER: informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE"
162                                pkill faucet
163                                if ps aux | grep -v grep | grep "faucet 4000"
164                                then
165                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
166                                else
167                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
168                                fi
169                                case "${PROTOCOL^^}" in
170                                        MULTICAST)
171                                                ogEcho log session "[29] Transferencia Multicast"
172                                                ogEcho log "ogMcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONMCASTSERVER $TOOLCLONE $COMPRESOR"
173                                                ogMcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONMCASTSERVER $TOOLCLONE $COMPRESOR || RETVAL=$?
174                                        ;;
175                                        UNICAST)
176                                                sleep 60
177                                                ogEcho log session "[29] Transferencia Unicast"
178                                                ogEcho log "ogUcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONUCASTSERVER $TOOLCLONE $COMPRESOR"
179                                                ogUcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONUCASTSERVER $TOOLCLONE $COMPRESOR || RETVAL=$?
180                                        ;;
181                                esac
182                               
183                                #if [ $REDSIZE -lt $SIZE ]; then
184                                #       echo "[85] Redimensionar partición a $SIZE KB."
185                                #       ogSetPartitionSize $2 $3 $SIZE
186                                        ogEcho log session "[90] Extender sistema de archivos."
187                                        ogExtendFs $2 $3
188                                #fi
189                                pkill faucet
190                                if [ $RETVAL == 0 ]
191                                then
192                                        exit 0
193                                else
194                                    exit $(ogRaiseError $OG_ERR_MCASTSENDPARTITION "Error al enviar la particion  $2 $3 con protocolo $PROTOCOL l167"; echo $?)
195                                fi
196
197                        ;;
198                        SENDFILE)                               
199                                ogEcho log session "[5] Master en modo  $MODEMASTER: informacion inicial a los clientes-slaves"
200                                ogEcho log session "[10]: Preparando Imagen: $IMG"
201                                TOOLCLONE=$(ogGetImageProgram $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "TOOLCLONE no detectado l174"; echo $?)
202                                COMPRESOR=$(ogGetImageCompressor $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "COMPRESOR NO DETECTADO l175"; echo $?)
203                                REDSIZE=$(ogGetImageSize $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "REDSIZE NO DETECTADO l176"; echo $?)
204                                ogEcho log session "[25] Master en Modo $MODEMASTER"
205                                ogEcho log "Informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE"
206                                if ps aux | grep -v grep | grep "faucet 4000"
207                                then
208                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
209                                else
210                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
211                                fi
212                                case "${PROTOCOL^^}" in
213                                        MULTICAST)
214                                                echo "[29] ogMcastSendFile $2 $3.img $SESSIONMCASTSERVER "
215                                                ogMcastSendFile  $2 $3.img $SESSIONMCASTSERVER  || RETVAL=$?
216                                                ;;
217                                        UNICAST)
218                                                sleep 60
219                                                echo "[29] ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER"
220                                                ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER || RETVAL=$?
221                                        ;;
222                                esac                                                   
223                                pkill faucet   
224                                if [ $RETVAL == 0 ]
225                                then
226                                        exit 0
227                                else
228                                        exit $(ogRaiseError $OG_ERR_MCASTSENDFILE "Error al enviar la image $2 $3.img con protocolo $PROTOCOL l200"; echo $?)
229                                fi
230                        ;;
231                esac
232                # FIN Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}
233        ;;
234        *)     
235                ogEcho log session "[1] Equipo -Client- preparando para recibir datos $PROTOCOL"
236                ogDiskToDev $DISKTARGET $PARTTARGET &>/dev/null || exit $(ogRaiseError $OG_ERR_LOCKED "El cliente no tiene esas particiones $DISKTARGET $PARTTARGET l211"; echo $?)     
237                # TODO: si el cliente no está en la lista de clientes UNICAST salir.
238                case "${PROTOCOL^^}" in
239                        UNICAST)
240                                echo "$SESSIONUCASTSERVER" | grep $HOSTIP || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER "Este cliente no pertence a la sesion UNICAST l214"; echo $?)
241                        ;;
242                esac   
243                ogEcho log session "[2] Desmontando particion destino"
244                ogUnmount $DISKTARGET $PARTTARGET || exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar la particion destino $2 $3  l218"; echo $?)
245                ogEcho log session  "[25] Buscando informacion extra sobre la clonacion con el master $MASTERIP: "
246                sleep 10
247                TIMEWAITMASTER=120
248                TIMEWAITING=0
249                GETINFO="NONE"
250                while [ "${GETINFO}" != "OK" ]
251                do
252                        INFOEXTRA=`hose $MASTERIP 4000 --in cat 2>/dev/null`
253                        sleep 10; echo -n "."
254                        #echo comienza el timeout $TIMEWAITMASTER para abortar
255                        [ -z "$INFOEXTRA" ] && let TIMEWAITMASTER=$TIMEWAITMASTER-10
256                        [ "$TIMEWAITMASTER" -gt "0" ] || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER " l230 "; echo $?)
257                        #Si primer parametro desde el server es READY, salimos del bucle
258                        GETINFO=$(echo $INFOEXTRA | awk '{print $1}')
259                        [ "$GETINFO" == "READY" ] && GETINFO="OK"
260                done           
261                echo $INFOEXTRA
262                TOOLCLONE=$(echo $INFOEXTRA | awk '{print $2}')
263                COMPRESOR=$(echo $INFOEXTRA | awk '{print $3}')
264                SIZEIMAGE=$(echo $INFOEXTRA | awk '{print $4}')
265                ogEcho log "$INFOEXTRA = herramienta= $TOOLCLONE  compresor= $COMPRESOR size= $SIZEIMAGE"
266                ogMount $DISKTARGET $PARTTARGET || ogFormat $DISKTARGET $PARTTARGET
267                SIZEPARTTARGET=$(parted `ogDiskToDev $DISKTARGET $PARTTARGET` unit kB print | grep Disk | awk -F" " '{print $3}' | tr -d kB);
268
269                ogEcho log session  "[28] comprobando que el tamaño de la imagen $SIZEIMAGE es menor que el de la particion destino $SIZEPARTTARGET"
270                # comprobamos que el tamaño de a imagen es menor que la del cliente.
271                if [ "$SIZEIMAGE" -lt "$SIZEPARTTARGET" ]
272                then                           
273                        ogEcho log session "[30] Iniciando Cliente $PROTOCOL "
274                                case "${PROTOCOL^^}" in
275                                        MULTICAST)
276                                                ogEcho log session  "ogMcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONMCASTCLIENT $TOOLCLONE $COMPRESOR"
277                                                ogMcastReceiverPartition "$DISKTARGET" "$PARTTARGET" "$SESSIONMCASTCLIENT" "$TOOLCLONE" "$COMPRESOR"  || exit $(ogRaiseError $OG_ERR_MCASTRECEIVERPARTITION " l251 "; echo $?)
278                                        ;;
279                                        UNICAST)
280                                                ogEcho log session "ogUcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONUCASTCLIENT $TOOLCLONE $COMPRESOR"
281                                                ogUcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONUCASTCLIENT $TOOLCLONE $COMPRESOR || exit $(ogRaiseError $OG_ERR_UCASTRECEIVERPARTITION " l230 "; echo $?)
282                                        ;;
283                                esac                                           
284                        if which configureOsCustom &>/dev/null; then
285                                ogEcho log session "[90] configureOsCustom $DISKTARGET $PARTTARGET"
286                                configureOsCustom $DISKTARGET $PARTTARGET
287                        else
288                                ogEcho log session "[90] $MSG_SCRIPTS_OS_CONFIGURE $DISKTARGET $PARTTARGET"
289                                configureOs $DISKTARGET $PARTTARGET                     
290                        fi
291
292                else
293                    # Si el tamaño de los datos recibidos es más grande que la particion destino
294                        ogRaiseError $OG_ERR_IMGSIZEPARTITION "ERROR tamanio particion= $SIZEPARTTARGET  menor que la imagen= $SIZEIMAGE"; exit $?
295                fi
296        ;;
297esac
298TIME=$[SECONDS-TIME1]
299ogEcho log session "[100] Duración de la operación $[TIME/60]m $[TIME%60]s"
300
Note: See TracBrowser for help on using the repository browser.