source: client/shared/scripts/updateCache @ 01a36ca

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 01a36ca was 9cd6cd3, checked in by adv <adv@…>, 13 years ago

1.0.3 #479 #469 #470 updateCache engine.cfg

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

  • Property mode set to 100755
File size: 6.2 KB
RevLine 
[914d834]1#!/bin/bash
2
3
[841ce50]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-
[a323383]8#@param 2 str_fichero   nombre del fichero a actualizar.
[841ce50]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 
[9cd6cd3]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-
[841ce50]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
[1547c12]25#@version 1.0.1 - Control de espacio requerido
26#@author  Antonio J.Doblas Viso
27#@date   2011-05-10
[841ce50]28#*/ ##
[914d834]29
30PROG="$(basename $0)"
[cea6d44]31if [ $# -lt 3 ]; then
[914d834]32    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE"
33    exit $?
34fi
35
[9cd6cd3]36#Carga del configurador del engine
37[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
38
[a323383]39REPOSITORIO="$1"
40PROTOCOLO="$3"
41OPTPROTOCOLO="$4"
[9b6e62c]42REPOIP=$(ogGetRepoIp)
43echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
[9cd6cd3]44echo "inicio"
45# Si el repositorio local CACHE no existe error 15.
[914d834]46if ! $(ogFindCache >/dev/null); then
[5c44f86]47        ogRaiseError $OG_ERR_NOTCACHE "CACHE"
[914d834]48        exit $?
49fi
50
[9cd6cd3]51echo "Comprobamos si Actualizacion - existe una imagen con igual nombre pero distinto sum-"
[9b6e62c]52#TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum-
[db8fdd2]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
[9cd6cd3]58CACHESIZE=$(ogGetCacheSize)
[914d834]59CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`)
[a323383]60FILESIZE=$(ls -sk $(ogGetPath $REPOSITORIO "$2") | cut -f1 -d" ")
[914d834]61
[9cd6cd3]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" ] 
[914d834]66then
[9cd6cd3]67        echo "ERROR: El tamanio del fichero $2 = $FILESIZE es mayor que el tamanaño de la cache = $CACHESIZE" | tee -a $OGLOGSESSION $OGLOGFILE
[5c44f86]68        ogRaiseError $OG_ERR_CACHESIZE "CACHE"
69    exit $?
[914d834]70fi
71
[9cd6cd3]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
[a323383]101ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
[db8fdd2]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
[914d834]105
[a323383]106ogMountCache >/dev/null
[914d834]107
108## Si no existe, crear subdirectorio para el fichero en la cache.
[a323383]109IMGDIR=$(ogGetParentPath CACHE "/$2")
[914d834]110if [ $? != 0 ]; then
111    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
[a323383]112    ogMakeDir CACHE $(dirname "/$2")
113    IMGDIR=$(ogGetParentPath CACHE "/$2") || exit $?
[914d834]114fi
115
[0c42ccf]116TIME1=$SECONDS
[914d834]117
118case "$PROTOCOLO" in
119        torrent | TORRENT )
[a323383]120                echo "ogCopyFile $1 $2.torrent absolute $OGCAC/$OGIMG"
[ec051d0]121                # tiempos
122                timewait=$(expr $(printf '%d\n' 0x$(ogGetMacAddress | awk -F: '{print $5$6}')) \* 120 / 65535)                         
[a323383]123                ogCopyFile $REPOSITORIO "$2.torrent" "$IMGDIR"
[9b6e62c]124                #TODO: comprobar que el tracker definido en el fichero es correcto.
125        #TODO comprobar que el fichero torrent está en cache
[ec051d0]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"
129                sleep $P2PWAIT
[a323383]130                ogTorrentStart CACHE "$2.torrent" $4
[914d834]131        ;;
132        multicast | MULTICAST )
[9b6e62c]133                echo "determinando puerto principal y auxiliar."
134                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
135                let PORTAUX=$PORT+1
[e8460d2]136        #TODO: ticket 379
137                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
138                sleep $NUMBER
139                #FIN TODO
[9b6e62c]140                echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) "
141                if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
142                then
[a323383]143                        ogMcastReceiverFile $PORT CACHE "$2"
[9b6e62c]144                else
[e8460d2]145                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
[9b6e62c]146                        echo "solicita la apertura:  hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO""
147                        hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
148                        #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2"
[e8460d2]149                        sleep 10
150                        if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
151                        then
[a323383]152                                ogMcastReceiverFile $PORT CACHE "$2"
[e8460d2]153                        else
154                            echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
155                            exit 1
156                        fi
157                fi     
[914d834]158        ;;
159        unicast | UNICAST )
[9b6e62c]160                echo "unicast"
[a323383]161                ogCopyFile $REPOSITORIO "$2" "$IMGDIR"
[914d834]162        ;;
163esac
164
[0c42ccf]165TIME1=$[SECONDS-TIME1]
166echo "tiempo de updateCache (descarga) $[TIME1/60]m $[TIME1%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
[914d834]167
[9cd6cd3]168echo "iniciando el calculo del crc de la imagen descargada" | tee -a $OGLOGSESSION $OGLOGFILE
[0c42ccf]169TIME2=$SECONDS
[a323383]170ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
[0c42ccf]171TIME2=$[SECONDS-TIME2]
172echo "tiempo de calculo crc $[TIME2/60]m $[TIME2%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
173
[db8fdd2]174# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
175[ "$RETVAL" == "0" ] && exit 1
176[ "$RETVAL" == "1" ] && exit 0
[a323383]177[ "$RETVAL" -gt  "1" ] && exit 1
178
Note: See TracBrowser for help on using the repository browser.