Highly Available and Scalable Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
7.2 KiB

  1. #!/bin/bash
  2. #EuryBOX update functions file
  3. #Desc: update hypervisor
  4. #1 arg required: operating_system
  5. eurybox_update_hv ()
  6. {
  7. local UPDATE_OUT
  8. local OS=$1
  9. local EURYBOX_HV_UPDATED=0
  10. local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
  11. while [[ ( $EURYBOX_HV_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
  12. do
  13. case $OS in
  14. fedora20|fedora21|centos7|redhat7|centos6|redhat6|centos5|redhat5 )
  15. UPDATE_OUT=`sudo yum -y update 2>&1`
  16. ;;
  17. fedora22|fedora23|fedora24 )
  18. UPDATE_OUT=`sudo dnf -y update 2>&1`
  19. ;;
  20. debian6|debian7|debian8|ubuntu12|ubuntu14|ubuntu16 )
  21. UPDATE_OUT=`sudo apt-get -y update && apt-get -y upgrade 2>&1`
  22. ;;
  23. openbsd5 )
  24. UPDATE_OUT=`echo "Not Implemented Yet"`
  25. ;;
  26. gentoo )
  27. UPDATE_OUT=`sudo emerge --sync && sudo emerge -uDU --with-bdeps=y @world && sudo emerge -av --depclean && sudo emerge --update --newuse --deep @world && sudo revdep-rebuild -v 2>&1`
  28. ;;
  29. archlinux )
  30. UPDATE_OUT=`sudo pacman -Syy && sudo pacman -Su 2>&1`
  31. ;;
  32. * )
  33. eurybox_display_message error UPDATE "OS unknown : $OS"
  34. ;;
  35. esac
  36. STATUS=$?
  37. if [[ $STATUS -eq 0 ]]
  38. then
  39. EURYBOX_HV_UPDATED=1
  40. else
  41. NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
  42. eurybox_display_message debug UPDATE "Hypervisor update failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
  43. sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
  44. fi
  45. done
  46. if [[ $NB_TRY_LEFT -eq 0 ]]
  47. then
  48. eurybox_display_message warning UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
  49. else
  50. eurybox_display_message message UPDATE "Hypervisor update OK"
  51. eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
  52. fi
  53. }
  54. #Desc: update vm
  55. #5 args required: vm_name vm_host vm_user vm_ssh_port operating_system
  56. eurybox_update_vm ()
  57. {
  58. local UPDATE_OUT
  59. local NAME=$1
  60. local HOST=$2
  61. local USER=$3
  62. local PORT=$4
  63. local OS=$5
  64. local EURYBOX_VM_UPDATED=0
  65. local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
  66. while [[ ( $EURYBOX_VM_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
  67. do
  68. case $OS in
  69. fedora20|fedora21|centos7|redhat7|centos6|redhat6|centos5|redhat5 )
  70. UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "yum -y update" 2>&1`
  71. ;;
  72. fedora22|fedora23|fedora24 )
  73. UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "dnf -y update" 2>&1`
  74. ;;
  75. debian6|debian7|debian8|ubuntu12|ubuntu14|ubuntu16 )
  76. UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "apt-get -y update && apt-get -y upgrade" 2>&1`
  77. ;;
  78. openbsd5 )
  79. UPDATE_OUT=`echo "Not Implemented Yet"`
  80. ;;
  81. gentoo )
  82. UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "emerge --sync && emerge -uDU --with-bdeps=y @world && emerge -av --depclean && emerge --update --newuse --deep @world && revdep-rebuild -v" 2>&1`
  83. ;;
  84. archlinux )
  85. UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "pacman -Syy && pacman -Su" 2>&1`
  86. ;;
  87. * )
  88. eurybox_display_message error UPDATE "OS unknown : $OS"
  89. ;;
  90. esac
  91. STATUS=$?
  92. if [[ $STATUS -eq 0 ]]
  93. then
  94. EURYBOX_VM_UPDATED=1
  95. else
  96. NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
  97. eurybox_display_message debug UPDATE "VM $NAME update failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
  98. sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
  99. fi
  100. done
  101. if [[ $NB_TRY_LEFT -eq 0 ]]
  102. then
  103. eurybox_display_message error UPDATE "VM $NAME - update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
  104. else
  105. eurybox_display_message message UPDATE "VM $NAME - update OK"
  106. eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
  107. fi
  108. }
  109. #Desc: update local repository
  110. #1 arg required: operating_system
  111. eurybox_update_local_repository ()
  112. {
  113. local UPDATE_OUT
  114. local REPO_UPDATED_NUM
  115. local REPO_ERRORS
  116. local REPO_PATH=${EURYBOX_UPDATE_LOCAL_REPOSITORIES_PATH}
  117. local OS=$1
  118. local EURYBOX_REPO_UPDATED=0
  119. local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
  120. eurybox_display_message message UPDATE "Updating local repositories"
  121. while [[ ( $EURYBOX_REPO_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
  122. do
  123. REPO_UPDATED_NUM=0
  124. REPO_ERRORS=""
  125. for (( REPO_NUM=1;REPO_NUM<=${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER};REPO_NUM++ ))
  126. do
  127. NAME=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},NAME]}
  128. ARCH=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},ARCH]}
  129. URI=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},URI]}
  130. eurybox_display_message message UPDATE "Updating repository : $NAME - arch: $ARCH - uri: $URI"
  131. MKDIR_OUT=`sudo mkdir -p ${REPO_PATH}/${NAME}/${ARCH}`
  132. UPDATE_OUT=`sudo sh -c "rsync $EURYBOX_RSYNC_OPTIONS --include=**${ARCH}** --include=*/ --exclude=* $URI ${REPO_PATH}/${NAME}/${ARCH}" 2>&1`
  133. STATUS=$?
  134. if [[ $STATUS -eq 0 ]]
  135. then
  136. eurybox_display_message debug UPDATE "Local repository $NAME - $URI - Clone OK"
  137. eurybox_display_message debug UPDATE "Mkdir command output:\n$MKDIR_OUT"
  138. eurybox_display_message debug UPDATE "Clone command output:\n$UPDATE_OUT"
  139. #TODO:MAC MASK
  140. UPDATE_OUT=`sudo chmod -R 555 ${REPO_PATH}/${NAME}/${ARCH} 2>&1`
  141. STATUS=$?
  142. if [[ $STATUS -eq 0 ]]
  143. then
  144. eurybox_display_message debug UPDATE "Local repository $NAME - MAC permissions change OK"
  145. eurybox_display_message message UPDATE "Local repository $NAME - $URI - Update OK"
  146. REPO_UPDATED_NUM=$(( ${REPO_UPDATED_NUM} + 1 ))
  147. else
  148. if [[ $REPO_ERRORS = "" ]]
  149. then
  150. REPO_ERRORS="${NAME}:\n${UPDATE_OUT}"
  151. else
  152. REPO_ERRORS="${REPO_ERRORS}\n\n${NAME}:\n${UPDATE_OUT}"
  153. fi
  154. eurybox_display_message debug UPDATE "Local repository $NAME MAC permissions change failed - trying others - error $STATUS:\n$UPDATE_OUT"
  155. fi
  156. else
  157. if [[ $REPO_ERRORS = "" ]]
  158. then
  159. REPO_ERRORS="${NAME}:\n${UPDATE_OUT}"
  160. else
  161. REPO_ERRORS="${REPO_ERRORS}\n\n${NAME}:\n${UPDATE_OUT}"
  162. fi
  163. eurybox_display_message debug UPDATE "Local repository $NAME clone failed - trying others - error $STATUS:\n$UPDATE_OUT"
  164. fi
  165. if [[ $REPO_NUM -eq ${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER} ]]
  166. then
  167. if [[ $REPO_UPDATED_NUM -eq ${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER} ]]
  168. then
  169. EURYBOX_REPO_UPDATED=1
  170. else
  171. NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
  172. eurybox_display_message debug UPDATE "Local repositories update failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds\n$NB_TRY_LEFT left"
  173. sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
  174. fi
  175. fi
  176. done
  177. done
  178. if [[ $NB_TRY_LEFT -eq 0 ]]
  179. then
  180. eurybox_display_message warning UPDATE "Local repositories update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - persistent errors:\n${REPO_ERRORS}"
  181. else
  182. eurybox_display_message message UPDATE "Local repositories update success"
  183. fi
  184. }
  185. ##TODO: SCRIPT AUTO DEPLOY LOCAL REPOS IN SERVICES VM