Commit b689d083 authored by Guillaume REMBERT's avatar Guillaume REMBERT

Fix non-TTY envs + local repositories as option + better failure management

parent 031c3950
-------------------------------
Project: EuryBOX
Version: 1.0.0
Date: 2016/04/02
Status: beta
-------------------------------
Author(s):
Guillaume REMBERT
......@@ -53,8 +53,8 @@ FIXME: TBD / Features, supported platforms, etc
-------------------------------
\ cfg (ConFiGuration): configuration files
-------------------------------
\ hw (HardWare): TBD
\ sw (SoftWare): TBD
\ hw (HardWare): physical configuration elements
\ sw (SoftWare): logical configuration elements
-------------------------------
\ doc (DOCumentation): documentation
-------------------------------
......
#!/bin/bash
#EuryBOX configuration file
#Script has to be run with sudo permissions
#To be run from crontab:
#/etc/sudoers ==> #Defaults requiretty
#/etc/sudoers ==> #Defaults !visiblepw
#crontab -e ==> * * * * * flock -n /eurybox-install-dir/update.lock -c /eurybox-install-dir/sw/src/exploitation_center/core/update/eurybox_update >> /eurybox-install-dir/update.log 2>&1
###################################
### SCRIPT EXECUTION PARAMETERS ###
###################################
......@@ -11,15 +19,19 @@ EURYBOX_CORPORATE="My Corporate"
#Can be: debug, verbose, info, warning or error
EURYBOX_LOG_LEVEL="info"
#Max retry on failure before stopping execution
EURYBOX_MAX_RETRY_ON_FAILURE="5"
EURYBOX_MAX_RETRY_ON_FAILURE="10"
#Errors temporisation time between trials (in seconds)
EURYBOX_ERROR_TEMPORISATION_TIME="5"
#Network calls timeout (in seconds)
EURYBOX_NETWORK_TIMEOUT="1"
EURYBOX_NETWORK_TIMEOUT="2"
#Version
EURYBOX_VERSION="1.0"
#Folder used for temporary operations
EURYBOX_TMP_FOLDER="/tmp/bkp"
##############################
### ENVIRONMENT PARAMETERS ###
##############################
......@@ -49,22 +61,19 @@ EURYBOX_SERVICES=(
[1,PORT]="22"
[1,USER]="root"
[1,OS]="openbsd5"
# [1,DISK]="/vm_storage/images/gw001m_dvd.iso"
## [1,SERV]="GATEWAY"
## [1,TYPE]="pf"
[1,DISK]=""
[2,NAME]="srv001m"
[2,HOST]="srv001m.$EURYBOX_DOMAIN"
[2,PORT]="22"
[2,USER]="root"
[2,OS]="centos7"
# [2,DISK]="/vm_storage/images/srv001m_hdd1.qcow2 /vm_storage/images/srv001m_hdd2.qcow2 /home/vm_store/service001b.qcow2"
## [2,SERV]="DHCP"
## [2,TYPE]="dhcpd"
[2,DISK]="/isos_store/additionnaldisk1.iso /isos_store/additionnaldisk2.iso"
)
#Services number (linked to the number of parameters per service)
#Should not have to be changed
EURYBOX_SERVICES_NUMBER=`expr ${#EURYBOX_SERVICES[@]} / 5`
EURYBOX_SERVICES_NUMBER=`expr ${#EURYBOX_SERVICES[@]} / 6`
#########################
......@@ -86,7 +95,7 @@ EURYBOX_BACKUP_LOW_CRITICAL_LEVEL="20000000"
#Post-Backup Commands
#Backup targets (in addition to services attached disks backup and additionnal disks from config)
#Backup targets (in addition to services attached disks and optionnal additionnal disks from config)
EURYBOX_BACKUP_TARGETS=(
# [0]="/var/log"
# [1]="/etc"
......@@ -144,26 +153,45 @@ EURYBOX_BACKUP_DESTINATION=(
[PASSWORD]="MyStrongFTPPassword"
)
##########################
### RESTORE PARAMETERS ###
##########################
#Restore target configuration
#Can be: interactive
#interactive => prompt from shell for restore target
EURYBOX_RESTORE_PARAMETERS_ACQUISITION="interactive"
#Restore type
#Can be: cloned_vm, cloned_full, full
#cloned_vm => restore vm(s) from archive as is
#cloned_full => restore hv as vm(s) from archive as is
#full => restore hv as vm(s) and refresh configurations elements
EURYBOX_RESTORE_TYPE="cloned_vm"
#Restore mode
#Can be: safe/fast
#safe => verify archive to ensure recovery process security
#fast => disable some verifications on archive to speedup recovery speed
EURYBOX_RESTORE_MODE="safe"
#########################
### UPDATE PARAMETERS ###
#########################
declare -A EURYBOX_UPDATE_LOCAL_REPOSITORIES
#Activation of local repositories update
#Can be: true/false
EURYBOX_UPDATE_LOCAL_REPOSITORIES_ACTIVATED="true"
#Local repositories storage path
EURYBOX_UPDATE_LOCAL_REPOSITORIES_PATH="/home/local_repositories"
#Target repositories
#NB: URI scheme follow rsync conventions / read rsync man to get all details
EURYBOX_UPDATE_LOCAL_REPOSITORIES=(
[1,NAME]="centos7"
......@@ -178,18 +206,20 @@ EURYBOX_UPDATE_LOCAL_REPOSITORIES=(
[4,NAME]="archlinux"
[4,ARCH]="x86_64"
[4,URI]="fooo.biz::archlinux/"
[5,NAME]="ubuntu16"
[5,ARCH]="amd64"
[5,URI]="archive.ubuntu.com::ubuntu/dists/xenial/"
[5,NAME]="ubuntu"
[5,ARCH]=""
[5,URI]="archive.ubuntu.com::ubuntu/"
[6,NAME]="fedora24"
[6,ARCH]="x86_64"
[6,URI]="fr2.rpmfind.net::linux/fedora/linux/releases/24/"
[7,NAME]="debian8"
[7,ARCH]="arm64"
[7,URI]="ftp.fr.debian.org::debian/dists/jessie/"
[7,NAME]="debian"
[7,ARCH]=""
[7,URI]="ftp.fr.debian.org::debian/"
)
EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER=`expr ${#EURYBOX_UPDATE_LOCAL_REPOSITORIES[@]} / 3`
###############################
### EXEC COMMAND PARAMETERS ###
###############################
......@@ -205,3 +235,11 @@ EURYBOX_EXEC_COMMANDS=(
[2,OS]="all"
)
EURYBOX_EXEC_COMMANDS_NUMBER=`expr ${#EURYBOX_EXEC_COMMANDS[@]} / 2`
#TODO: ADD HOSTED SERVICE CONFIGURATION MANAGEMENT
## [1,SERV]="GATEWAY"
## [1,TYPE]="pf"
## [2,SERV]="DHCP"
## [2,TYPE]="dhcpd"
......@@ -76,9 +76,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in 5 seconds - error $STATUS\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT"
case $BKP_PROTOCOL in
......@@ -87,9 +87,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target NFS server not registred on destination - trying to contact again in 5 seconds - error $STATUS:\n$NFS_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning BACKUP "Backup target NFS server not registred on destination - trying to contact again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$NFS_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT\n$NFS_OUT"
MOUNT_OUT=`sudo mount $MOUNT_OPTIONS $EURYBOX_MNT_NFS_OPTIONS -o proto=tcp,port=${BKP_PORT} -t $BKP_TYPE ${BKP_HOST}:${BKP_DEST} ${BKP_MOUNT} 2>&1`
......@@ -97,8 +97,8 @@ eurybox_backup_mount_target ()
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target NFS mount failed and target folder is empty - trying to mount again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
eurybox_display_message warning BACKUP "Backup target NFS mount failed and target folder is empty - trying to mount again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
fi
;;
......@@ -108,9 +108,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup SSH server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in 5 seconds - error $STATUS:\n$SSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning BACKUP "Backup SSH server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$SSH_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT\n$SSH_OUT"
MOUNT_OUT=`sshfs $EURYBOX_MNT_SSHFS_OPTIONS -p $BKP_PORT ${BKP_USER}@${BKP_HOST}:${BKP_DEST} ${BKP_MOUNT} 2>&1`
......@@ -118,8 +118,8 @@ eurybox_backup_mount_target ()
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target SSHFS mount failed - trying to mount again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
eurybox_display_message warning BACKUP "Backup target SSHFS mount failed - trying to mount again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
fi
;;
......@@ -129,9 +129,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in 5 seconds - error $STATUS:\n$FTP_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$FTP_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT\n$FTP_OUT"
MOUNT_OUT=`sudo curlftpfs $EURYBOX_MNT_FTPFS_OPTIONS ftp://${BKP_USER}:${BKP_PASSWORD}@${BKP_HOST}:${BKP_PORT}${BKP_DEST} ${BKP_MOUNT} 2>&1`
......@@ -139,8 +139,8 @@ eurybox_backup_mount_target ()
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target FTPFS mount failed - trying to mount again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
eurybox_display_message warning BACKUP "Backup target FTPFS mount failed - trying to mount again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
fi
;;
......@@ -153,9 +153,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} not found - trying to detect device again in 5 seconds - error $STATUS:\n$PART_OUT\n$NB_TRY_LEFT left"
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} not found - trying to detect device again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$PART_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
else
eurybox_display_message message BACKUP "Backup device partition ${BKP_PART} detected"
eurybox_display_message debug BACKUP "Partition detection command output:\n$PART_OUT"
......@@ -163,9 +163,9 @@ eurybox_backup_mount_target ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} mount failed - trying to mount partition again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} mount failed - trying to mount partition again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
fi
;;
......@@ -270,8 +270,8 @@ eurybox_backup_umount_target ()
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target unmount failed and target folder is not empty. Trying to unmount again in 5 seconds - error $STATUS\n$UMOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
eurybox_display_message warning BACKUP "Backup target unmount failed and target folder is not empty. Trying to unmount again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS\n$UMOUNT_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
;;
* )
......
......@@ -95,7 +95,7 @@ eurybox_check_configuration ()
eurybox_display_message message CHECK "Hypervisor: ${EURYBOX_HYPERVISOR[*]}"
for ((EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=$EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++));
do
eurybox_display_message message CHECK "Target service: host:${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]}, name: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}, ssh user: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]}, ssh port: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}, OS: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,OS]}, disks: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,DISK]}"
eurybox_display_message message CHECK "Target service: host:${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]}, name: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}, ssh user: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]}, ssh port: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}, OS: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,OS]}, additional disks: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,DISK]}"
done
eurybox_display_message debug CHECK "Services number: $EURYBOX_SERVICES_NUMBER"
fi
......@@ -154,6 +154,7 @@ eurybox_check_configuration ()
eurybox_display_message error CHECK "Bad hypervisor type: ${EURYBOX_HYPERVISOR[TYPE]}"
;;
esac
EURYBOX_RSYNC_OPTIONS="-azHmS --timeout=$EURYBOX_NETWORK_TIMEOUT"
EURYBOX_SSH_OPTIONS="-oPasswordAuthentication=no -oConnectTimeout=$EURYBOX_NETWORK_TIMEOUT -oConnectionAttempts=$EURYBOX_MAX_RETRY_ON_FAILURE"
EURYBOX_NMAP_OPTIONS="--host-timeout $EURYBOX_NETWORK_TIMEOUT --max-retries $EURYBOX_MAX_RETRY_ON_FAILURE"
EURYBOX_LS_OPTIONS="-x"
......@@ -163,6 +164,7 @@ eurybox_check_configuration ()
case $EURYBOX_LOG_LEVEL in
debug )
set -xv
EURYBOX_RSYNC_OPTIONS+=" -v"
EURYBOX_SSH_OPTIONS+=" -oLogLevel=debug"
EURYBOX_NMAP_OPTIONS+=" -d9 -v3"
EURYBOX_LS_OPTIONS+=" -a"
......@@ -173,6 +175,7 @@ eurybox_check_configuration ()
;;
verbose )
set -v
EURYBOX_RSYNC_OPTIONS+=" -v"
EURYBOX_SSH_OPTIONS+=" -oLogLevel=verbose"
EURYBOX_NMAP_OPTIONS+=" -d0 -v2"
EURYBOX_LS_OPTIONS+=" -l"
......@@ -201,13 +204,14 @@ eurybox_check_configuration ()
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=error"
;;
esac
eurybox_display_message debug CHECK "ssh options: $EURYBOX_SSH_OPTIONS"
eurybox_display_message debug CHECK "nmap options: $EURYBOX_NMAP_OPTIONS"
eurybox_display_message debug CHECK "ftpfs mount options: $EURYBOX_MNT_FTPFS_OPTIONS"
eurybox_display_message debug CHECK "ls options: $EURYBOX_LS_OPTIONS"
eurybox_display_message debug CHECK "virsh options: $EURYBOX_VIRSH_OPTIONS"
eurybox_display_message debug CHECK "nfs mount options: $EURYBOX_MNT_NFS_OPTIONS"
eurybox_display_message debug CHECK "nmap options: $EURYBOX_NMAP_OPTIONS"
eurybox_display_message debug CHECK "rsync options: $EURYBOX_RSYNC_OPTIONS"
eurybox_display_message debug CHECK "ssh options: $EURYBOX_SSH_OPTIONS"
eurybox_display_message debug CHECK "sshfs mount options: $EURYBOX_MNT_SSHFS_OPTIONS"
eurybox_display_message debug CHECK "ftpfs mount options: $EURYBOX_MNT_FTPFS_OPTIONS"
eurybox_display_message debug CHECK "virsh options: $EURYBOX_VIRSH_OPTIONS"
}
#Desc: verify the archive ECCF and try to repair it
......
......@@ -85,7 +85,7 @@ eurybox_create_archive_tar ()
fi
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error CREATE "Archive creation failed - error: $STATUS:\n$TAR_OUT"
eurybox_display_message warning CREATE "Archive creation failed - error: $STATUS:\n$TAR_OUT"
else
eurybox_display_message message CREATE "Archive creation - OK"
eurybox_display_message debug CREATE "Tar command output:\n$TAR_OUT"
......
......@@ -13,8 +13,6 @@ euryboxctrl_check_all_vm_halted ()
euryboxctrl_check_all_services_halted ()
{
#Check that no vm at all are still running
## EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '(NR>2) && ($0 != "") {print $2}'`
local EURYBOX_VM_NAME
#Check that no services vm are still running
for ((EURYBOX_SERVICES_NUM=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM>=1;EURYBOX_SERVICES_NUM--));
......@@ -99,6 +97,7 @@ euryboxctrl_create_sign ()
euryboxctrl_discover_available_archives ()
{
local LNAME
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup origin"
eurybox_backup_mount_target
......
......@@ -64,47 +64,68 @@ eurybox_display_message ()
debug )
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
tput setb 0
tput setaf 6
if [ -t 1 ]
then
tput setb 0
tput setaf 6
fi
printf "$NOW [EURYBOX][$CATEGORY][DEBUG] %b\n" "$MESSAGE"
fi
;;
message )
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "info" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
tput setb 0
tput setaf 2
if [ -t 1 ]
then
tput setb 0
tput setaf 2
fi
printf "$NOW [EURYBOX][$CATEGORY][INFO] %b\n" "$MESSAGE"
fi
;;
warning )
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "info" || $EURYBOX_LOG_LEVEL = "verbose" || $EURYBOX_LOG_LEVEL = "warning" ]]
then
tput setb 0
tput setaf 1
if [ -t 1 ]
then
tput setb 0
tput setaf 1
fi
printf "$NOW [EURYBOX][$CATEGORY][WARNING] %b\n" "$MESSAGE"
fi
;;
error )
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "info" || $EURYBOX_LOG_LEVEL = "verbose" || $EURYBOX_LOG_LEVEL = "warning" || $EURYBOX_LOG_LEVEL = "error" ]]
then
tput setb 0
tput setaf 1
printf "$NOW [EURYBOX][$CATEGORY][ERROR] %b\n" "$MESSAGE"
tput setb 0
tput sgr0
printf "Stopping script execution\n"
exit 1
if [ -t 1 ]
then
tput setb 0
tput setaf 1
fi
printf "$NOW [EURYBOX][$CATEGORY][ERROR] %b\n" "$MESSAGE"
if [ -t 1 ]
then
tput setb 0
tput sgr0
fi
printf "Stopping script execution\n"
exit 1
fi
;;
* )
tput sgr0
* )
if [ -t 1 ]
then
tput sgr0
fi
printf "$NOW [EURYBOX][SYNTAX][ERROR] Bad log level message. Stopping script execution\n"
exit 1
;;
esac
tput setb 0
tput sgr0
if [ -t 1 ]
then
tput setb 0
tput sgr0
fi
}
#Desc: echo detected archives, sorted by name, year and month
......@@ -283,9 +304,9 @@ eurybox_exec_ssh_command ()
eurybox_display_message message TOOLS "Command execution - OK: $CMD"
eurybox_display_message debug TOOLS "Command execution output:\n$CMD_OUT"
else
eurybox_display_message warning TOOLS "Command execution failed - trying again in 5 seconds - error $STATUS:\n$CMD_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
eurybox_display_message warning TOOLS "Command execution failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds - error $STATUS:\n$CMD_OUT\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
......
......@@ -40,12 +40,13 @@ eurybox_update_hv ()
EURYBOX_HV_UPDATED=1
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "Hypervisor update failed - trying again - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
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"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
eurybox_display_message warning UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
else
eurybox_display_message message UPDATE "Hypervisor update OK"
eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
......@@ -95,7 +96,8 @@ eurybox_update_vm ()
EURYBOX_VM_UPDATED=1
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "VM $NAME update failed - trying again - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
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"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
......@@ -130,11 +132,11 @@ eurybox_update_local_repository ()
URI=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},URI]}
eurybox_display_message message UPDATE "Updating repository : $NAME - arch: $ARCH - uri: $URI"
MKDIR_OUT=`sudo mkdir -p ${REPO_PATH}/${NAME}/${ARCH}`
UPDATE_OUT=`sudo sh -c "rsync -avzHm --include=**${ARCH}** --include=*/ --exclude=* $URI ${REPO_PATH}/${NAME}/${ARCH}" 2>&1`
UPDATE_OUT=`sudo sh -c "rsync $EURYBOX_RSYNC_OPTIONS --include=**${ARCH}** --include=*/ --exclude=* $URI ${REPO_PATH}/${NAME}/${ARCH}" 2>&1`
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message UPDATE "Local repository $NAME - $URI - clone OK"
eurybox_display_message debug UPDATE "Local repository $NAME - $URI - Clone OK"
eurybox_display_message debug UPDATE "Mkdir command output:\n$MKDIR_OUT"
eurybox_display_message debug UPDATE "Clone command output:\n$UPDATE_OUT"
#TODO:MAC MASK
......@@ -142,7 +144,8 @@ eurybox_update_local_repository ()
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message UPDATE "Local repository $NAME - MAC permissions change OK"
eurybox_display_message debug UPDATE "Local repository $NAME - MAC permissions change OK"
eurybox_display_message message UPDATE "Local repository $NAME - $URI - Update OK"
REPO_UPDATED_NUM=$(( ${REPO_UPDATED_NUM} + 1 ))
else
if [[ $REPO_ERRORS = "" ]]
......@@ -169,14 +172,15 @@ eurybox_update_local_repository ()
EURYBOX_REPO_UPDATED=1
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "Local repositories update failed - trying again\n$NB_TRY_LEFT left"
eurybox_display_message debug UPDATE "Local repositories update failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds\n$NB_TRY_LEFT left"
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
fi
done
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error UPDATE "Local repositories update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - persistent errors:\n${REPO_ERRORS}"
eurybox_display_message warning UPDATE "Local repositories update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - persistent errors:\n${REPO_ERRORS}"
else
eurybox_display_message message UPDATE "Local repositories update success"
fi
......
......@@ -102,6 +102,7 @@ eurybox_vm_shutdown_acpi ()
{
local NAME=$1
local STATUS
local VIRSH_OUT
#Waiting for the VM to be stopped
local EURYBOX_VM_NAME
local EURYBOX_VM_STATE=1
......@@ -116,29 +117,44 @@ eurybox_vm_shutdown_acpi ()
else
if [[ $EURYBOX_VM_STOPPED -eq 0 ]]
then
sudo virsh $EURYBOX_VIRSH_OPTIONS shutdown $NAME
VIRSH_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS shutdown $NAME 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning VM "Error on vm $NAME stop - trying again in 5 seconds / $NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - stop failed - error $STATUS:\n$VIRSH_OUT\nTrying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds / $NB_TRY_LEFT left"
else
EURYBOX_VM_STOPPED=1
eurybox_display_message message VM "Successfully initiated vm $NAME stop - waiting for vm poweroff"
eurybox_display_message message VM "Successfully initiated VM $NAME stop - waiting for vm poweroff"
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
fi
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - still running - trying again in 5 seconds / $NB_TRY_LEFT left"
eurybox_display_message debug VM "VM $NAME - still running - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds / $NB_TRY_LEFT left"
fi
sleep 5
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error VM "VM $NAME - stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE: $EURYBOX_VM_NAME"
eurybox_display_message warning VM "VM $NAME - ACPI stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE:\n$EURYBOX_VM_NAME\n error $STATUS:\n$VIRSH_OUT\nForcing stop"
VIRSH_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS destroy $NAME 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error VM "VM $NAME - forced stop failed - error $STATUS:\n$VIRSH_OUT"
else
eurybox_display_message message VM "Successfully initiated VM $NAME forced stop"
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ -z "$EURYBOX_VM_NAME" ]]
then
eurybox_display_message message VM "VM $NAME - forced stop OK"
else
eurybox_display_message error VM "VM $NAME - forced stop failed - VM still running:\n$EURYBOX_VM_NAME"
fi
fi
else
eurybox_display_message message VM "VM $NAME - stop OK"
eurybox_display_message message VM "VM $NAME - ACPI stop OK"
fi
}
......@@ -155,6 +171,7 @@ eurybox_vm_shutdown_ssh ()
local STATUS
local EURYBOX_VM_NAME
local SSH_OUT
local VIRSH_OUT
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_VM_STATE -eq 1 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
......@@ -169,25 +186,40 @@ eurybox_vm_shutdown_ssh ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning VM "VM $NAME - stop failed - trying again in 5 seconds:\n$SSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - SSH stop failed - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds:\n$SSH_OUT\n$NB_TRY_LEFT left"
else
EURYBOX_VM_STOPPED=1
eurybox_display_message message VM "Successfully initiated vm $NAME stop - waiting for vm poweroff"
eurybox_display_message debug VM "Successfully initiated vm $NAME stop - waiting for vm poweroff"
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
fi
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - still running - trying again in 5 seconds:\n$EURYBOX_VM_NAME\n$NB_TRY_LEFT left"
eurybox_display_message debug VM "VM $NAME - still running - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds:\n$EURYBOX_VM_NAME\n$NB_TRY_LEFT left"
fi
sleep 5
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error VM "VM $NAME - stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE:\n$EURYBOX_VM_NAME"
eurybox_display_message warning VM "VM $NAME - SSH stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE:\n$EURYBOX_VM_NAME\n error $STATUS:\n$SSH_OUT\nForcing stop"
VIRSH_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS destroy $NAME 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error VM "VM $NAME - forced stop failed - error $STATUS:\n$VIRSH_OUT"
else
eurybox_display_message message VM "Successfully initiated VM $NAME forced stop"
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ -z "$EURYBOX_VM_NAME" ]]
then
eurybox_display_message message VM "VM $NAME - forced stop OK"
else
eurybox_display_message error VM "VM $NAME - forced stop failed - VM still running:\n$EURYBOX_VM_NAME"
fi
fi
else
eurybox_display_message message VM "VM $NAME - stop OK"
eurybox_display_message message VM "VM $NAME - SSH stop OK"
fi
}
......@@ -224,8 +256,8 @@ eurybox_vm_start ()
VM_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ -z "$VM_OUT" ]]
then
eurybox_display_message warning VM "Error on vm $NAME start - trying again in 5 seconds:\n$VIRSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "Error on vm $NAME start - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds:\n$VIRSH_OUT\n$NB_TRY_LEFT left"
else
eurybox_display_message debug VM "VM $NAME already running - waiting for network contact"
EURYBOX_VM_STARTED=1
......@@ -238,16 +270,16 @@ eurybox_vm_start ()
fi
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - still unreachable - trying again in 5 seconds\n$EURYBOX_VM_AVAILABLE\n$NB_TRY_LEFT left"
eurybox_display_message debug VM "VM $NAME - still unreachable - trying again in ${EURYBOX_ERROR_TEMPORISATION_TIME} seconds\n$EURYBOX_VM_AVAILABLE\n$NB_TRY_LEFT left"
fi
sleep 5
sleep ${EURYBOX_ERROR_TEMPORISATION_TIME}
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error VM "VM $NAME - start failed - no network contact after $EURYBOX_MAX_RETRY_ON_FAILURE"
eurybox_display_message warning VM "VM $NAME - start failed - no network contact after $EURYBOX_MAX_RETRY_ON_FAILURE:\n${EURYBOX_VM_AVAILABLE}"
else
eurybox_display_message debug VM "VM $NAME - start OK"
eurybox_display_message message VM "VM $NAME - start OK"
fi
}
......@@ -42,8 +42,11 @@ eurybox_display_message message STATUS "$EURYBOX_CORPORATE update script started
#Make sure all VM are started
euryboxctrl_start_services
#Update local repository
euryboxctrl_update_local_repository
if [[ ${EURYBOX_UPDATE_LOCAL_REPOSITORIES_ACTIVATED} = "true" ]]
then
#Update local repository
euryboxctrl_update_local_repository
fi
#Update the physical machine
euryboxctrl_update_hypervisor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment