source: client/shared/scripts/cloneRemoteFromMaster @ ca0f67c6

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 ca0f67c6 was 44eeffb, checked in by adv <adv@…>, 13 years ago

#469 uso de engine.cfg

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

  • Property mode set to 100755
File size: 13.5 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
60#test 1. cliente sin particiones.    Detectado  TODO: crear estrucutras de particiones
61#test 2. cliente con particion mas pequeña. Detectado.
62#test 3. cleinte con particion destinio no formateado.  Detectado.
63#test 4. cliente con particion destino ocupado por el usuario pwd .  FALLO.
64#test 5. master sin origen particion.
65#test 6. master sin origen fichero.
66
67#Carga del configurador del engine
68[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
69
70
71trap "pkill faucet; exit 1" 0 1 2 3 6 9 14 15
72
73TIME1=$SECONDS
74PROG="$(basename $0)"
75if [ $# -lt 1 -o "$1" == "help" ]; then
76        echo "cloneRemoteFromMaster ipmaster disk init [MULTICAST|UNICAST] session disk part tool comp"
77        exit 1
78fi
79
80if [  $# -lt 6  ]; then
81    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ipMaster SOURCE_disco SOURCE_particion [MULTICAT|UNICAST] SESSION TARGER_disck TARGET_partition"
82    exit $?
83fi
84
85# Obtener información de los parámetros de entrada.
86HOSTIP=`ogGetIpAddress`
87if [ -z "$HOSTIP" ]
88then
89        source /tmp/net-eth*
90        HOSTIP=`ogGetIpAddress`
91fi
92MASTERIP=$1
93PROTOCOL=$4
94case $PROTOCOL in
95        MULTICAST|multicast)
96                SESSIONMCASTSERVER=$5
97                SESSIONMCASTCLIENT=`echo $5 | awk -F: '{print $1}'`
98        ;;
99        UNICAST|unicast)
100                SESSIONUCASTSERVER=$5
101        SESSIONUCASTCLIENT=`echo $5 | awk -F: '{print $1}'`:$MASTERIP
102    ;;
103    *)
104     exit $(ogRaiseError $OG_ERR_FORMAT "Protocolo $PROTOCOL no soportado en esta operacion"; echo $?)
105    ;;
106esac
107# contenedor destino (disco particion)
108DISKTARGET=$6
109PARTTARGET=$7
110#herramienta de compresión.
111TOOLCLONE=$8
112COMPRESOR=$9
113
114pkill faucet
115
116# Preparando Instrucción según sea Master o Client
117case $MASTERIP in
118        $HOSTIP)
119                echo "[1] Equipo Master preparando el origen de los datos a enviar"
120                ogGetPath $2 $3.img &>/dev/null; RC=$?;
121                ogDiskToDev $2 $3 &>/dev/null; RETVAL=$?;
122
123                if [ "$RC" == "0" ]; then
124                        IMG=$(ogGetPath $2 $3.img); MODEMASTER=SENDFILE
125                elif [ "$RETVAL" == "0" ]; then
126                        DISKSOURCE=$2; PARTSOURCE=$3; MODEMASTER=SENDPARTITION
127                else
128                        ogRaiseError $OG_ERR_NOTFOUND "$2 $3"; exit $?
129                fi
130                echo $MODEMASTER
131                # Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}                                   
132                case "$MODEMASTER" in
133                        SENDPARTITION)
134                                echo "[5] Master en modo  $MODEMASTER: informacion inicial a los clientes-slaves" | tee -a $OGLOGSESSION $OGLOGFILE
135                                if ps aux | grep -v grep | grep "faucet 4000"
136                                then
137                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 118"; exit $?     
138                                else
139                                        faucet 4000 --out echo "WORKING" &     
140                                fi                             
141                                echo "[10]: Desmontando DISK:$DISKSOURCE PARTITION:$PARTSOURCE" | tee -a $OGLOGSESSION $OGLOGFILE
142                                ogUnmount $2 $3 ||  exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar $2 $3  l124"; echo $?)
143                                #Obtener tamaño de la partición.
144                                SIZE=$(ogGetPartitionSize $2 $3)  || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar tamaño partcion $2 $3  l127"; echo $?)
145                               
146                                if [ "$OGWINREDUCE" == "TRUE"   ]
147                                then
148                                                echo "[15]: Calculando la reduccion del sistema de archivos DISK:$DISKSOURCE PARTITION:$PARTSOURCE SIZE:$SIZE" | tee -a $OGLOGSESSION $OGLOGFILE
149                                                ogReduceFs $2 $3 || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al reducir el FS $2 $3  l129"; echo $?)
150                                fi
151                                       
152                                REDSIZE=$(ogGetFsSize $2 $3) || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar el nuevo FS $2 $3  l130"; echo $?)     
153                                TIMEAUX=$[SECONDS-TIME1]
154                                echo "[20]: Preparada para enviar el sistema de archivos: Tamaño datos: $REDSIZE  origne: $DISKSOURCE $PARTSOURCE" | tee -a $OGLOGSESSION $OGLOGFILE
155                                echo "      tiempo de reducción del sistema de archivos: $[TIMEAUX/60]m $[TIMEAUX%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
156                               
157                                #if [ $REDSIZE -lt $SIZE ]; then
158                        #               echo "[24] Redimensionar partición a $REDSIZE KB."
159                        #               ogSetPartitionSize $2 $3 $REDSIZE
160                                #fi
161
162                                echo "[25] Master en Modo $MODEMASTER: informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE" | tee -a $OGLOGSESSION $OGLOGFILE
163                                pkill faucet
164                                if ps aux | grep -v grep | grep "faucet 4000"
165                                then
166                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
167                                else
168                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
169                                fi
170                                case $PROTOCOL in
171                                        MULTICAST|multicast)
172                                                echo "[29] ogMcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONMCASTSERVER $TOOLCLONE $COMPRESOR"  | tee -a $OGLOGSESSION $OGLOGFILE
173                                                ogMcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONMCASTSERVER $TOOLCLONE $COMPRESOR || RETVAL=$?
174                                        ;;
175                                        UNICAST|unicast)
176                                                sleep 60
177                                                echo "[29] ogUcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONUCASTSERVER $TOOLCLONE $COMPRESOR" | tee -a $OGLOGSESSION $OGLOGFILE
178                                                ogUcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONUCASTSERVER $TOOLCLONE $COMPRESOR || RETVAL=$?
179                                        ;;
180                                esac   
181                               
182                                #if [ $REDSIZE -lt $SIZE ]; then
183                                #       echo "[85] Redimensionar partición a $SIZE KB."
184                                #       ogSetPartitionSize $2 $3 $SIZE
185                                        echo "[90] Extender sistema de archivos." | tee -a $OGLOGSESSION $OGLOGFILE
186                                        ogExtendFs $2 $3
187                                #fi
188                                pkill faucet
189                                if [ $RETVAL == 0 ]
190                                then
191                                        exit 0
192                                else
193                                    exit $(ogRaiseError $OG_ERR_MCASTSENDPARTITION "Error al enviar la particion  $2 $3 con protocolo $PROTOCOL l167"; echo $?)
194                                fi
195                               
196                        ;;
197                        SENDFILE)                               
198                                echo "[5] Master en modo  $MODEMASTER: informacion inicial a los clientes-slaves"
199                                echo "[10]: Preparando Imagen: $IMG"
200                                TOOLCLONE=$(ogGetImageProgram $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "TOOLCLONE no detectado l174"; echo $?)
201                                COMPRESOR=$(ogGetImageCompressor $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "COMPRESOR NO DETECTADO l175"; echo $?)
202                                REDSIZE=$(ogGetImageSize $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "REDSIZE NO DETECTADO l176"; echo $?)
203                                echo "[25] Master en Modo $MODEMASTER: informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE"
204                                if ps aux | grep -v grep | grep "faucet 4000"
205                                then
206                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
207                                else
208                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
209                                fi                             
210                                case $PROTOCOL in
211                                        MULTICAST|multicast)
212                                                echo "[29] ogMcastSendFile $2 $3.img $SESSIONMCASTSERVER "
213                                                ogMcastSendFile  $2 $3.img $SESSIONMCASTSERVER  || RETVAL=$?
214                                                ;;
215                                        UNICAST|unicast)
216                                                sleep 60
217                                                echo "[29] ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER"
218                                                ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER || RETVAL=$?
219                                        ;;
220                                esac                                                   
221                                pkill faucet   
222                                if [ $RETVAL == 0 ]
223                                then
224                                        exit 0
225                                else
226                                    exit $(ogRaiseError $OG_ERR_MCASTSENDFILE "Error al enviar la image $2 $3.img con protocolo $PROTOCOL l200"; echo $?)
227                                fi
228                        ;;
229                esac
230                # FIN Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}
231        ;;
232        *)     
233                echo "[1] Equipo -Client- preparando para recibir datos $PROTOCOL" | tee -a $OGLOGSESSION $OGLOGFILE
234                ogDiskToDev $DISKTARGET $PARTTARGET &>/dev/null || exit $(ogRaiseError $OG_ERR_LOCKED "El cliente no tiene esas particiones $DISKTARGET $PARTTARGET l211"; echo $?)     
235                # TODO: si el cliente no está en la lista de clientes UNICAST salir.
236                case $PROTOCOL in
237                        UNICAST|unicast)
238                                echo "$SESSIONUCASTSERVER" | grep $HOSTIP || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER "Este cliente no pertence a la sesion UNICAST l214"; echo $?)
239                        ;;
240                esac   
241                echo "[2] Desmontando particion destino" | tee -a $OGLOGSESSION $OGLOGFILE       
242                ogUnmount $DISKTARGET $PARTTARGET || exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar la particion destino $2 $3  l218"; echo $?)
243                echo -n "[25] Buscando informacion extra sobre la clonacion con el master $MASTERIP: " | tee -a $OGLOGSESSION $OGLOGFILE
244                sleep 10
245                TIMEWAITMASTER=120
246                TIMEWAITING=0
247                GETINFO="NONE"
248                while [ "${GETINFO}" != "OK" ]
249                do
250                        INFOEXTRA=`hose $MASTERIP 4000 --in cat 2>/dev/null`
251                        sleep 10; echo -n "."
252                        #echo comienza el timeout $TIMEWAITMASTER para abortar
253                        [ -z "$INFOEXTRA" ] && let TIMEWAITMASTER=$TIMEWAITMASTER-10
254                        [ "$TIMEWAITMASTER" -gt "0" ] || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER " l230 "; echo $?)
255                        #Si primer parametro desde el server es READY, salimos del bucle
256                        GETINFO=$(echo $INFOEXTRA | awk '{print $1}')
257                        [ "$GETINFO" == "READY" ] && GETINFO=OK
258                done           
259                echo $INFOEXTRA
260                TOOLCLONE=$(echo $INFOEXTRA | awk '{print $2}')
261                COMPRESOR=$(echo $INFOEXTRA | awk '{print $3}')
262                SIZEIMAGE=$(echo $INFOEXTRA | awk '{print $4}')
263                echo "[26] $INFOEXTRA = herramienta= $TOOLCLONE  compresor= $COMPRESOR size= $SIZEIMAGE " | tee -a $OGLOGSESSION $OGLOGFILE
264                ogMount $DISKTARGET $PARTTARGET || ogFormat $DISKTARGET $PARTTARGET
265                #SIZEPARTTARGET=$(parted `ogDiskToDev $DISKTARGET $PARTTARGET` unit kB print | awk '{y=x; x=$4};END{print y}' | tr -d kB)
266                SIZEPARTTARGET=$(parted `ogDiskToDev $DISKTARGET $PARTTARGET` unit kB print | grep Disk | awk -F" " '{print $3}' | tr -d kB);
267
268                echo "[28] comprobando que el tamaño de la imagen $SIZEIMAGE es menor que el de la particion destino $SIZEPARTTARGET"    | tee -a $OGLOGSESSION $OGLOGFILE
269                # comprobamos que el tamaño de a imagen es menor que la del cliente.
270                if [ "$SIZEIMAGE" -lt "$SIZEPARTTARGET" ]
271                then                           
272                        echo "[30] Iniciando Cliente $PROTOCOL " | tee -a $OGLOGSESSION $OGLOGFILE
273                                case $PROTOCOL in
274                                        MULTICAST|multicast)
275                                                echo "ogMcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONMCASTCLIENT $TOOLCLONE $COMPRESOR" | tee -a $OGLOGSESSION $OGLOGFILE
276                                                ogMcastReceiverPartition "$DISKTARGET" "$PARTTARGET" "$SESSIONMCASTCLIENT" "$TOOLCLONE" "$COMPRESOR"  || exit $(ogRaiseError $OG_ERR_MCASTRECEIVERPARTITION " l251 "; echo $?)
277                                        ;;
278                                        UNICAST|unicast)
279                                                echo "ogUcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONUCASTCLIENT $TOOLCLONE $COMPRESOR" | tee -a $OGLOGSESSION $OGLOGFILE
280                                                ogUcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONUCASTCLIENT $TOOLCLONE $COMPRESOR || exit $(ogRaiseError $OG_ERR_UCASTRECEIVERPARTITION " l230 "; echo $?)
281                                        ;;
282                                esac                                           
283                        echo "[90] llamando a configureOS $DISKTARGET $PARTTARGET" | tee -a $OGLOGSESSION $OGLOGFILE
284                        configureOs $DISKTARGET $PARTTARGET                     
285                else
286                    # Si el tamaño de los datos recibidos es más grande que la particion destino
287                        ogRaiseError $OG_ERR_IMGSIZEPARTITION "ERROR tamanio particion= $SIZEPARTTARGET  menor que la imagen= $SIZEIMAGE"; exit $?
288                fi
289        ;;
290esac
291TIME=$[SECONDS-TIME1]
292echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
293
294
Note: See TracBrowser for help on using the repository browser.