source: client/shared/scripts/updateCache @ fe08e1b

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

#470 updateCache registra tasa de transferenica torrent y multicast

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

  • Property mode set to 100755
File size: 6.4 KB
Line 
1#!/bin/bash
2
3
4#/**
5#         updateCache
6#@brief   Actualiza la cache del cliente con imagen o fichero iso.
7#@param 1 REPO          Origen del fichero. -accesible por nfs-samba-
8#@param 2 str_fichero   nombre del fichero a actualizar.
9#@param 3 str_protoco.  TORRENT | MULTICAST    | UNICAST.
10#@param 4 str_opcionesprotocolo
11#@param 4 str_opcionesupdatecache
12#@ejemplo: oneRemoteFromMaster 172.17.36.11 CACHE /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
13#@return 
14#@exception OG_ERR_FORMAT       formato incorrecto.
15#@exception OG_ERR_NOTCACHE     No existe cache -15-
16#@exception $OG_ERR_CACHESIZE   Tamaño de la paticion menor al archivo a descargar -16-
17#@note   
18#@todo:
19#@version 0.9.1 - integracion EAC
20#@author  Antonio J. Doblas Viso. Universidad de Malaga.
21#@date    2008/03/17
22#@version 0.9.2 - integracion OpenGnsys
23#@author  Antonio J. Doblas Viso. Universidad de Malaga.
24#@date    2010/07/27
25#@version 1.0.1 - Control de espacio requerido
26#@author  Antonio J.Doblas Viso
27#@date   2011-05-10
28#*/ ##
29
30PROG="$(basename $0)"
31if [ $# -lt 3 ]; then
32    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE"
33    exit $?
34fi
35
36#Carga del configurador del engine
37[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
38
39REPOSITORIO="$1"
40PROTOCOLO="$3"
41OPTPROTOCOLO="$4"
42REPOIP=$(ogGetRepoIp)
43echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
44echo "inicio"
45# Si el repositorio local CACHE no existe error 15.
46if ! $(ogFindCache >/dev/null); then
47        ogRaiseError $OG_ERR_NOTCACHE "CACHE"
48        exit $?
49fi
50
51echo "Comprobamos si Actualizacion - existe una imagen con igual nombre pero distinto sum-"
52#TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum-
53ogUpdateCacheIsNecesary $1 $2; RETVAL=$?
54# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
55[ "$RETVAL" == "1" ] && exit 0
56[ "$RETVAL" -gt  "1" ] && exit 1
57
58CACHESIZE=$(ogGetCacheSize)
59CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`)
60FILESIZE=$(ls -sk $(ogGetPath $REPOSITORIO "$2") | cut -f1 -d" ")
61
62
63echo "Comprobar que el tamaño de la cache es mayor que el fichero a descargar."
64#ERROR CACHESIZE 16
65if [ "$FILESIZE" -ge "$CACHESIZE" ] 
66then
67        echo "ERROR: El tamanio del fichero $2 = $FILESIZE es mayor que el tamanaño de la cache = $CACHESIZE" | tee -a $OGLOGSESSION $OGLOGFILE
68        ogRaiseError $OG_ERR_CACHESIZE "CACHE"
69    exit $?
70fi
71
72echo "Comprobar el espacio libre de la cache y actuar según engine.cfg"
73#ERROR CACHESIZE 16
74if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] 
75then
76        # echo "[ ] No hay espacio sufiente en la CACHE, detectar que hacer con engine.cfg"  | tee -a $OGLOGSESSION $OGLOGFILE
77        case $ACTIONCACHEFULL in
78        NONE)
79                NEXTOPERATION=UNICAST
80        ;;
81        FORMAT)
82            echo "[51] Formatear la cache "  | tee -a $OGLOGSESSION $OGLOGFILE
83            ogUnmountCache
84            ogFormatCache
85            ogMountCache
86            NEXTOPERATION=REPEAT
87        ;;
88        DELETE)
89                echo "[51] elimar las imágenes rm -fr $OGCAC$OGIMG/* "  | tee -a $OGLOGSESSION $OGLOGFILE
90            rm -fr  $OGCAC$OGIMG/*
91            NEXOPERATION=REPEAT
92        ;;
93        *)
94                echo "ERROR: El tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE" | tee -a $OGLOGSESSION $OGLOGFILE
95                ogRaiseError $OG_ERR_CACHESIZE "CACHE"
96        exit $?
97        ;;
98        esac   
99fi
100
101ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
102# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
103[ "$RETVAL" == "1" ] && exit 0
104[ "$RETVAL" -gt  "1" ] && exit 1
105
106ogMountCache >/dev/null
107
108## Si no existe, crear subdirectorio para el fichero en la cache.
109IMGDIR=$(ogGetParentPath CACHE "/$2")
110if [ $? != 0 ]; then
111    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
112    ogMakeDir CACHE $(dirname "/$2")
113    IMGDIR=$(ogGetParentPath CACHE "/$2") || exit $?
114fi
115
116TIME1=$SECONDS
117
118case "$PROTOCOLO" in
119        torrent | TORRENT )
120                echo "ogCopyFile $1 $2.torrent absolute $OGCAC/$OGIMG"
121                # tiempos
122                timewait=$(expr $(printf '%d\n' 0x$(ogGetMacAddress | awk -F: '{print $5$6}')) \* 120 / 65535)                         
123                ogCopyFile $REPOSITORIO "$2.torrent" "$IMGDIR"
124                #TODO: comprobar que el tracker definido en el fichero es correcto.
125        #TODO comprobar que el fichero torrent está en cache
126                # retardamos el inicio -aleatorio de 0 a 120 segundos- al tracker para gestionar mas de +-40 equipos
127                P2PWAIT=$[ ( $RANDOM % 120 )  + 1 ]
128                echo "   [ ] Esperando $P2PWAIT segundos para iniciar ogTorrentStart CACHE $2.torrent $4" | tee -a $OGLOGSESSION $OGLOGFILE
129                sleep $P2PWAIT
130                ogTorrentStart CACHE "$2.torrent" $4
131                RESUMEUPDATECACHE=$(cat $OGLOGCOMMAND | grep -B1 "Download")
132        ;;
133        multicast | MULTICAST )
134                echo "determinando puerto principal y auxiliar."
135                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
136                let PORTAUX=$PORT+1
137        #TODO: ticket 379
138                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
139                sleep $NUMBER
140                #FIN TODO
141                echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) "
142                if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
143                then
144                        ogMcastReceiverFile $PORT CACHE "$2"
145                else
146                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
147                        echo "solicita la apertura:  hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO""
148                        hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
149                        #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2"
150                        sleep 10
151                        if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
152                        then
153                                ogMcastReceiverFile $PORT CACHE "$2"
154                        else
155                            echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
156                            exit 1
157                        fi
158                fi     
159                RESUMEUPDATECACHE=$(cat $OGLOGCOMMAND.tmp | grep -B1 "Transfer complete")
160        ;;
161        unicast | UNICAST )
162                echo "unicast"
163                ogCopyFile $REPOSITORIO "$2" "$IMGDIR"
164        ;;
165esac
166
167TIME1=$[SECONDS-TIME1]
168echo "   [ ] $RESUMEUPDATECACHE " | tee -a $OGLOGSESSION $OGLOGFILE
169echo "   [ ] tiempo de updateCache (descarga) $[TIME1/60]m $[TIME1%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
170echo "   [ ] iniciando el calculo del crc de la imagen descargada" | tee -a $OGLOGSESSION $OGLOGFILE
171TIME2=$SECONDS
172ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
173TIME2=$[SECONDS-TIME2]
174echo "   [ ] tiempo de calculo crc $[TIME2/60]m $[TIME2%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
175
176# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
177[ "$RETVAL" == "0" ] && exit 1
178[ "$RETVAL" == "1" ] && exit 0
179[ "$RETVAL" -gt  "1" ] && exit 1
180
Note: See TracBrowser for help on using the repository browser.