mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Refactoring part I
This commit is contained in:
parent
a6b5ead259
commit
a60213a3e2
4 changed files with 1201 additions and 997 deletions
|
@ -79,6 +79,7 @@ fi
|
||||||
|
|
||||||
source "$script_dir/sub_scripts/lxc_launcher.sh"
|
source "$script_dir/sub_scripts/lxc_launcher.sh"
|
||||||
source "$script_dir/sub_scripts/testing_process.sh"
|
source "$script_dir/sub_scripts/testing_process.sh"
|
||||||
|
source "$script_dir/sub_scripts/log_extractor.sh"
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Vérifie la connexion internet.
|
# Vérifie la connexion internet.
|
||||||
|
@ -627,7 +628,6 @@ INIT_VAR() {
|
||||||
note=0
|
note=0
|
||||||
tnote=0
|
tnote=0
|
||||||
all_test=0
|
all_test=0
|
||||||
use_curl=0
|
|
||||||
|
|
||||||
MANIFEST_DOMAIN="null"
|
MANIFEST_DOMAIN="null"
|
||||||
MANIFEST_PATH="null"
|
MANIFEST_PATH="null"
|
||||||
|
@ -671,8 +671,8 @@ INIT_LEVEL() {
|
||||||
|
|
||||||
INIT_VAR
|
INIT_VAR
|
||||||
INIT_LEVEL
|
INIT_LEVEL
|
||||||
echo -n "" > "$COMPLETE_LOG" # Initialise le fichier de log
|
echo -n "" > "$complete_log" # Initialise le fichier de log
|
||||||
echo -n "" > "$RESULT" # Initialise le fichier des résulats d'analyse
|
echo -n "" > "$test_result" # Initialise le fichier des résulats d'analyse
|
||||||
echo -n "" | sudo tee "$script_dir/lxc_boot.log" # Initialise le fichier de log du boot du conteneur
|
echo -n "" | sudo tee "$script_dir/lxc_boot.log" # Initialise le fichier de log du boot du conteneur
|
||||||
if [ "$no_lxc" -eq 0 ]; then
|
if [ "$no_lxc" -eq 0 ]; then
|
||||||
LXC_INIT
|
LXC_INIT
|
||||||
|
@ -953,6 +953,7 @@ then
|
||||||
# Récupère le nom du job dans le CI
|
# Récupère le nom du job dans le CI
|
||||||
id=$(cat "$script_dir/../CI.lock") # Récupère l'id du job en cours
|
id=$(cat "$script_dir/../CI.lock") # Récupère l'id du job en cours
|
||||||
job=$(grep "$id" "$script_dir/../work_list" | cut -d ';' -f 3) # Et récupère le nom du job dans le work_list
|
job=$(grep "$id" "$script_dir/../work_list" | cut -d ';' -f 3) # Et récupère le nom du job dans le work_list
|
||||||
|
job=${job// /%20} # Replace all space by %20
|
||||||
if [ -n "$job" ]; then
|
if [ -n "$job" ]; then
|
||||||
job_log="/job/$job/lastBuild/console"
|
job_log="/job/$job/lastBuild/console"
|
||||||
fi
|
fi
|
||||||
|
@ -988,7 +989,7 @@ then # Si l'app est au niveau 0, et que le test tourne en CI, envoi un mail d'av
|
||||||
mail -s "[YunoHost] Échec d'installation d'une application dans le CI" "$dest" <<< "$message" # Envoi un avertissement par mail.
|
mail -s "[YunoHost] Échec d'installation d'une application dans le CI" "$dest" <<< "$message" # Envoi un avertissement par mail.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Le log complet des installations et suppressions est disponible dans le fichier $COMPLETE_LOG"
|
echo "Le log complet des installations et suppressions est disponible dans le fichier $complete_log"
|
||||||
# Clean
|
# Clean
|
||||||
rm -f "$OUTPUTD" "$temp_RESULT" "$script_dir/url_output" "$script_dir/curl_print" "$script_dir/manifest_extract"
|
rm -f "$OUTPUTD" "$temp_RESULT" "$script_dir/url_output" "$script_dir/curl_print" "$script_dir/manifest_extract"
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
OUTPUTD="$script_dir/debug_output.log"
|
temp_log="$script_dir/temp_yunohost-cli.log"
|
||||||
YUNOHOST_LOG="/var/log/yunohost/yunohost-cli.log"
|
# yunohost_log="/var/lib/lxc/$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log"
|
||||||
COMPLETE_LOG="$script_dir/Complete.log"
|
yunohost_log="/var/lib/lxc/pchecker_lxc/rootfs/var/log/yunohost/yunohost-cli.log"
|
||||||
temp_RESULT="$script_dir/temp_result.log"
|
complete_log="$script_dir/Complete.log"
|
||||||
|
temp_result="$script_dir/temp_result.log"
|
||||||
|
|
||||||
echo "Chargement des fonctions de log_extractor.sh"
|
echo "Load functions from log_extractor.sh"
|
||||||
|
|
||||||
ECHO_FORMAT () {
|
ECHO_FORMAT () {
|
||||||
|
# Simply an echo with color and typo
|
||||||
|
# $2 = color
|
||||||
|
# $3 = typo
|
||||||
|
# Last arg = clog
|
||||||
|
|
||||||
if [ "$2" == "red" ]; then
|
if [ "$2" == "red" ]; then
|
||||||
echo -en "\e[91m"
|
echo -en "\e[91m"
|
||||||
fi
|
fi
|
||||||
|
@ -29,71 +35,104 @@ ECHO_FORMAT () {
|
||||||
if [ "$3" == "underlined" ]; then
|
if [ "$3" == "underlined" ]; then
|
||||||
echo -en "\e[4m"
|
echo -en "\e[4m"
|
||||||
fi
|
fi
|
||||||
copy_log=--
|
local copy_log=--
|
||||||
|
# If 'clog' is given as argument, the echo command will be duplicated into the complete log.
|
||||||
if [ "$2" == "clog" ] || [ "$3" == "clog" ] || [ "$4" == "clog" ]; then
|
if [ "$2" == "clog" ] || [ "$3" == "clog" ] || [ "$4" == "clog" ]; then
|
||||||
copy_log="$COMPLETE_LOG"
|
copy_log="$complete_log"
|
||||||
fi
|
fi
|
||||||
echo -en "$1" | tee -a "$RESULT" "$copy_log"
|
echo -en "$1" | tee -a "$test_result" "$copy_log"
|
||||||
echo -en "\e[0m"
|
echo -en "\e[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
COPY_LOG () {
|
COPY_LOG () {
|
||||||
if [ "$1" -eq 1 ]; then
|
# Extract A small part of $yunohost_log.
|
||||||
log_line=$(sudo wc -l "$YUNOHOST_LOG" | cut -d ' ' -f 1) # Compte le nombre de ligne du fichier de log Yunohost
|
# $1 = 1 or 2. If '1', count the number of line of the current log file.
|
||||||
log_line=$(( $log_line + 1 )) # Ignore la première ligne, reprise de l'ancien log.
|
# If '2', copy the log from the last read line.
|
||||||
echo -n "" > "$OUTPUTD" # Efface le fichier de log temporaire
|
|
||||||
|
if [ $1 -eq 1 ]; then
|
||||||
|
# Count the number of lines in YunoHost log
|
||||||
|
log_line=$(sudo wc --lines "$yunohost_log" | cut --delimiter=' ' --fields=1)
|
||||||
|
# Ignore the first line, it's duplicated of the previous log
|
||||||
|
log_line=$(( $log_line + 1 ))
|
||||||
|
# Erase the temporary log
|
||||||
|
> "$temp_log"
|
||||||
fi
|
fi
|
||||||
if [ "$1" -eq 2 ]; then
|
if [ $1 -eq 2 ]; then
|
||||||
sudo tail -n +$log_line "$YUNOHOST_LOG" >> "$OUTPUTD" # Copie le fichier de log à partir de la dernière ligne du log préexistant
|
# Copy the log from the last read line
|
||||||
|
sudo tail --lines=+$log_line "$yunohost_log" >> "$temp_log"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
PARSE_LOG () {
|
PARSE_LOG () {
|
||||||
while read LOG_LIGNE_TEMP
|
# Print all errors and warning found in the log.
|
||||||
do # Lit le log pour extraire les warning et les erreurs.
|
|
||||||
if echo "$LOG_LIGNE_TEMP" | grep -q "^>ERROR: "; then
|
while read log_read_line
|
||||||
|
do
|
||||||
|
if echo "$log_read_line" | grep --quiet "^>ERROR: "; then
|
||||||
|
# Print a red "Error"
|
||||||
ECHO_FORMAT "Error:" "red" "underlined"
|
ECHO_FORMAT "Error:" "red" "underlined"
|
||||||
ECHO_FORMAT " $(echo "$LOG_LIGNE_TEMP\n" | sed 's/^>ERROR: //')" "red"
|
# And print the error itself
|
||||||
|
ECHO_FORMAT " $(echo "$log_read_line\n" | sed 's/^>ERROR: //')" "red"
|
||||||
YUNOHOST_RESULT=1
|
YUNOHOST_RESULT=1
|
||||||
YUNOHOST_REMOVE=1
|
YUNOHOST_REMOVE=1
|
||||||
fi
|
fi
|
||||||
if echo "$LOG_LIGNE_TEMP" | grep -q "^>WARNING: "; then
|
if echo "$log_read_line" | grep --quiet "^>WARNING: "; then
|
||||||
|
# Print a yellow "Warning:"
|
||||||
ECHO_FORMAT "Warning:" "lyellow" "underlined"
|
ECHO_FORMAT "Warning:" "lyellow" "underlined"
|
||||||
ECHO_FORMAT " $(echo "$LOG_LIGNE_TEMP\n" | sed 's/^>WARNING: //')" "lyellow"
|
# And print the warning itself
|
||||||
|
ECHO_FORMAT " $(echo "$log_read_line\n" | sed 's/^>WARNING: //')" "lyellow"
|
||||||
fi
|
fi
|
||||||
done < "$temp_RESULT"
|
done < "$temp_result"
|
||||||
}
|
}
|
||||||
|
|
||||||
CLEAR_LOG () {
|
CLEAR_LOG () {
|
||||||
# Élimine les warning parasites connus et identifiables facilement.
|
# Remove all knew useless warning lines.
|
||||||
sed -i '/^>WARNING: yunohost\.hook <lambda> - \[[[:digit:].]*\] *$/d' "$temp_RESULT" # Ligne de warning vide précédant et suivant la progression d'un wget
|
|
||||||
sed -i '/^>WARNING: yunohost\.hook <lambda> - \[[[:digit:].]*\] *[[:digit:]]*K \.* /d' "$temp_RESULT" # Ligne de warning de progression d'un wget
|
# Useless warnings from wget
|
||||||
sed -i '/% Total % Received % Xferd/d' "$temp_RESULT" # Ligne de warning des statistiques d'un wget
|
sed --in-place '/^>WARNING: yunohost\.hook <lambda> - \[[[:digit:].]*\] *$/d' "$temp_result" # Empty line foregoing wget progression
|
||||||
sed -i '/Dload Upload Total Spent/d' "$temp_RESULT" # 2e ligne de warning des statistiques d'un wget
|
sed --in-place '/^>WARNING: yunohost\.hook <lambda> - \[[[:digit:].]*\] *[[:digit:]]*K \.* /d' "$temp_result" # Wget progression
|
||||||
sed -i '/--:--:-- --:--:-- --:--:--/d' "$temp_RESULT" # 3e ligne de warning des statistiques d'un wget
|
sed --in-place '/% Total % Received % Xferd/d' "$temp_result" # Wget statistics
|
||||||
sed -i '/^>WARNING: yunohost.backup backup_restore - \[[[:digit:].]*\] YunoHost est déjà installé$/d' "$temp_RESULT" # Ligne de warning du backup car Yunohost est déjà installé
|
sed --in-place '/Dload Upload Total Spent/d' "$temp_result" # Wget statistics (again)
|
||||||
sed -i '/^$/d' "$temp_RESULT" # Retire les lignes vides
|
sed --in-place '/--:--:-- --:--:-- --:--:--/d' "$temp_result" # Wget statistics (Yes, again...)
|
||||||
|
|
||||||
|
# Useless warning from yunohost backup.
|
||||||
|
sed --in-place '/^>WARNING: yunohost.backup backup_restore - \[[[:digit:].]*\] YunoHost est déjà installé$/d' "$temp_result"
|
||||||
|
|
||||||
|
# Empty lines
|
||||||
|
sed --in-place '/^$/d' "$temp_result"
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_EXTRACTOR () {
|
LOG_EXTRACTOR () {
|
||||||
echo -n "" > "$temp_RESULT" # Initialise le fichier des résulats d'analyse
|
# Analyse the log to extract "warning" and "error" lines
|
||||||
cat "$OUTPUTD" >> "$COMPLETE_LOG"
|
|
||||||
while read LOG_LIGNE
|
|
||||||
do # Lit le log pour extraire les warning et les erreurs.
|
|
||||||
if echo "$LOG_LIGNE" | grep -q " ERROR "; then
|
|
||||||
echo -n ">ERROR: " >> "$temp_RESULT"
|
|
||||||
echo "$LOG_LIGNE" | sed 's/^.* ERROR *//' >> "$temp_RESULT"
|
|
||||||
fi
|
|
||||||
if echo "$LOG_LIGNE" | grep -q "yunohost.*: error:"; then # Récupère aussi les erreurs de la moulinette
|
|
||||||
echo -n ">ERROR: " >> "$temp_RESULT"
|
|
||||||
echo "$LOG_LIGNE" >> "$temp_RESULT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if echo "$LOG_LIGNE" | grep -q " WARNING "; then
|
# Copy the log from the last read line.
|
||||||
echo -n ">WARNING: " >> "$temp_RESULT"
|
COPY_LOG 2
|
||||||
echo "$LOG_LIGNE" | sed 's/^.* WARNING *//' >> "$temp_RESULT"
|
|
||||||
|
# Erase the temporary result file
|
||||||
|
> "$temp_result"
|
||||||
|
# Duplicate the part of the yunohost log into the complete log.
|
||||||
|
cat "$temp_log" >> "$complete_log"
|
||||||
|
while read log_read_line
|
||||||
|
do
|
||||||
|
if echo "$log_read_line" | grep --quiet " ERROR "
|
||||||
|
then
|
||||||
|
# Copy in the temporary result file all logged error
|
||||||
|
echo -n ">ERROR: " >> "$temp_result"
|
||||||
|
echo "$log_read_line" | sed 's/^.* ERROR *//' >> "$temp_result"
|
||||||
fi
|
fi
|
||||||
done < "$OUTPUTD"
|
if echo "$log_read_line" | grep --quiet "yunohost.*: error:"
|
||||||
CLEAR_LOG
|
then
|
||||||
PARSE_LOG
|
# Also copy the moulinette errors
|
||||||
|
echo -n ">ERROR: " >> "$temp_result"
|
||||||
|
echo "$log_read_line" >> "$temp_result"
|
||||||
|
fi
|
||||||
|
if echo "$log_read_line" | grep --quiet " WARNING "
|
||||||
|
then
|
||||||
|
# And all logged warning
|
||||||
|
echo -n ">WARNING: " >> "$temp_result"
|
||||||
|
echo "$log_read_line" | sed 's/^.* WARNING *//' >> "$temp_result"
|
||||||
|
fi
|
||||||
|
done < "$temp_log"
|
||||||
|
CLEAR_LOG # Remove all knew useless warning lines.
|
||||||
|
PARSE_LOG # Print all errors and warning found in the log.
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,133 +1,172 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ARG_SSH="-t"
|
# arg_ssh="-t"
|
||||||
# PLAGE_IP=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep PLAGE_IP= | cut -d '"' -f2)
|
arg_ssh="-tt"
|
||||||
# LXC_BRIDGE=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep LXC_BRIDGE= | cut -d '=' -f2)
|
|
||||||
# main_iface=$(cat "$script_dir/config" | grep iface= | cut -d '=' -f2)
|
|
||||||
|
|
||||||
echo -e "Chargement des fonctions de lxc_launcher.sh"
|
echo -e "Load functions from lxc_launcher.sh"
|
||||||
|
|
||||||
|
is_lxc_running () {
|
||||||
|
sudo lxc-info --name=$LXC_NAME | grep --quiet "RUNNING"
|
||||||
|
}
|
||||||
|
|
||||||
LXC_INIT () {
|
LXC_INIT () {
|
||||||
# Activation du bridge réseau
|
# Initialize LXC network
|
||||||
echo "Initialisation du réseau pour le conteneur."
|
|
||||||
sudo ifup $LXC_BRIDGE --interfaces=/etc/network/interfaces.d/$LXC_BRIDGE | tee -a "$RESULT" 2>&1
|
|
||||||
|
|
||||||
# Activation des règles iptables
|
# Activate the bridge
|
||||||
sudo iptables -A FORWARD -i $LXC_BRIDGE -o $main_iface -j ACCEPT | tee -a "$RESULT" 2>&1
|
echo "Initialize network for LXC."
|
||||||
sudo iptables -A FORWARD -i $main_iface -o $LXC_BRIDGE -j ACCEPT | tee -a "$RESULT" 2>&1
|
sudo ifup $LXC_BRIDGE --interfaces=/etc/network/interfaces.d/$LXC_BRIDGE | tee --append "$test_result" 2>&1
|
||||||
sudo iptables -t nat -A POSTROUTING -s $PLAGE_IP.0/24 -j MASQUERADE | tee -a "$RESULT" 2>&1
|
|
||||||
|
|
||||||
if [ "$no_lxc" -eq 0 ]; then
|
# Activate iptables rules
|
||||||
YUNOHOST_LOG=/var/lib/lxc/$LXC_NAME/rootfs$YUNOHOST_LOG #Prend le log de la machine lxc plutôt que celui de l'hôte
|
echo "Activate iptables rules."
|
||||||
fi
|
sudo iptables --append FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT | tee --append "$test_result" 2>&1
|
||||||
|
sudo iptables --append FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT | tee --append "$test_result" 2>&1
|
||||||
|
sudo iptables --table nat --append POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_START () {
|
LXC_START () {
|
||||||
if [ "$no_lxc" -eq 0 ]
|
# Start the lxc container and execute the given command in it
|
||||||
then
|
# $1 = Command to execute in the container
|
||||||
for i in `seq 1 3`
|
|
||||||
do # Tente jusqu'à 3 fois de démarrer le conteneur
|
# Try to start the container 3 times.
|
||||||
# Démarrage de la machine
|
local max_try=3
|
||||||
if sudo lxc-info --name $LXC_NAME | grep -q "STOPPED"; then
|
local i=0
|
||||||
sudo lxc-start -n $LXC_NAME -d --logfile "$script_dir/lxc_boot.log" | tee -a "$RESULT" 2>&1
|
for i in `seq 1 $max_try`
|
||||||
fi
|
do
|
||||||
for j in `seq 1 10`
|
# Start the container and log the booting process in $script_dir/lxc_boot.log
|
||||||
do # Vérifie que la machine est accessible en ssh avant de commencer. Il lui faut le temps de démarrer.
|
# Try to start only if the container is not already started
|
||||||
echo -n .
|
if ! is_lxc_running; then
|
||||||
if ssh $ARG_SSH $LXC_NAME "exit 0" > /dev/null 2>&1; then
|
sudo lxc-start --name=$LXC_NAME --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1
|
||||||
break
|
fi
|
||||||
fi
|
|
||||||
sleep 1
|
# Check during 20 seconds if the container has finished to start.
|
||||||
done
|
local j=0
|
||||||
failstart=0
|
for j in `seq 1 20`
|
||||||
sudo lxc-ls -f | grep $LXC_NAME | sed 's/- NO//'
|
do
|
||||||
if [ $(sudo lxc-info --name $LXC_NAME | grep -c "STOPPED") -ne 0 ]; then
|
echo -n .
|
||||||
ECHO_FORMAT "Le conteneur n'a pas démarré correctement...\n" "lred" "bold"
|
# Try to connect with ssh to check if the container is ready to work.
|
||||||
failstart=1
|
if ssh $arg_ssh $LXC_NAME "exit 0" > /dev/null 2>&1; then
|
||||||
if [ "$i" -ne 3 ]; then
|
# Break the for loop if the container is ready.
|
||||||
ECHO_FORMAT "Redémarrage du conteneur...\n" "lred" "bold"
|
break
|
||||||
fi
|
|
||||||
LXC_STOP
|
|
||||||
elif ! ssh $ARG_SSH $LXC_NAME "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?"; then # Si le conteneur a démarré, test sa connectivité.
|
|
||||||
ECHO_FORMAT "Le conteneur ne parvient pas à accéder à internet...\n" "lred" "bold"
|
|
||||||
failstart=1
|
|
||||||
if [ "$i" -ne 3 ]; then
|
|
||||||
ECHO_FORMAT "Redémarrage du conteneur...\n" "lred" "bold"
|
|
||||||
fi
|
|
||||||
LXC_STOP
|
|
||||||
else
|
|
||||||
break # Sort de la boucle for si le démarrage est réussi
|
|
||||||
fi
|
|
||||||
if [ "$i" -eq 3 ] && [ "$failstart" -eq 1 ]; then # Si le dernier démarrage est encore en erreur, stoppe le test
|
|
||||||
ECHO_FORMAT "Le conteneur a rencontré des erreurs 3 fois de suite...\nSi le problème persiste, utilisez le script lxc_check.sh pour vérifier et réparer le conteneur." "lred" "bold"
|
|
||||||
echo "Log de démarrage:"
|
|
||||||
cat "$script_dir/lxc_boot.log"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
sleep 1
|
||||||
done
|
done
|
||||||
scp -rq "$APP_CHECK" "$LXC_NAME": >> "$RESULT" 2>&1
|
|
||||||
ssh $ARG_SSH $LXC_NAME "$1 > /dev/null 2>> debug_output.log; exit \$?" >> "$RESULT" 2>&1 # Exécute la commande dans la machine LXC
|
local failstart=0
|
||||||
returncode=$?
|
# Check if the container is running
|
||||||
sudo cat "/var/lib/lxc/$LXC_NAME/rootfs/home/pchecker/debug_output.log" >> "$OUTPUTD" # Récupère le contenu du OUTPUTD distant pour le réinjecter dans le local
|
if ! is_lxc_running; then
|
||||||
return $returncode
|
ECHO_FORMAT "The LXC container didn't start...\n" "lred" "bold"
|
||||||
else # Sinon exécute la commande directement.
|
failstart=1
|
||||||
eval "$1" > /dev/null 2>> "$OUTPUTD"
|
if [ $i -ne $max_try ]; then
|
||||||
fi
|
ECHO_FORMAT "Rebooting the container...\n" "lred" "bold"
|
||||||
|
fi
|
||||||
|
LXC_STOP # Stop the LXC container
|
||||||
|
elif ! ssh $arg_ssh $LXC_NAME "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1
|
||||||
|
then
|
||||||
|
# Try to ping security.debian.org to check the connectivity from the container
|
||||||
|
ECHO_FORMAT "The container failed to connect to internet...\n" "lred" "bold"
|
||||||
|
failstart=1
|
||||||
|
if [ $i -ne $max_try ]; then
|
||||||
|
ECHO_FORMAT "Rebooting the container...\n" "lred" "bold"
|
||||||
|
fi
|
||||||
|
LXC_STOP # Stop the LXC container
|
||||||
|
else
|
||||||
|
# Break the for loop if the container is ready.
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Failed if the container failed to start
|
||||||
|
if [ $i -eq $max_try ] && [ $failstart -eq 1 ]
|
||||||
|
then
|
||||||
|
ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "lred" "bold"
|
||||||
|
ECHO_FORMAT "Boot log:\n" clog
|
||||||
|
cat "$script_dir/lxc_boot.log" | tee --append "$test_result"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Count the number of line of the current yunohost log file.
|
||||||
|
COPY_LOG 1
|
||||||
|
|
||||||
|
# Copy the package into the container.
|
||||||
|
scp -rq "$APP_CHECK" "$LXC_NAME": >> "$test_result" 2>&1
|
||||||
|
|
||||||
|
# Execute the command given in argument in the container and log its results.
|
||||||
|
ssh $arg_ssh $LXC_NAME "$1 > /dev/null 2>> temp_yunohost-cli.log; exit \$?" >> "$test_result" 2>&1
|
||||||
|
# Store the return code of the command
|
||||||
|
local returncode=$?
|
||||||
|
|
||||||
|
# Retrieve the log of the previous command and copy its content in the temporary log
|
||||||
|
sudo cat "/var/lib/lxc/$LXC_NAME/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log"
|
||||||
|
|
||||||
|
# Return the exit code of the ssh command
|
||||||
|
return $returncode
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_STOP () {
|
LXC_STOP () {
|
||||||
if [ "$no_lxc" -eq 0 ]
|
# Stop and restore the LXC container
|
||||||
then
|
|
||||||
# Arrêt de la machine virtualisée
|
local snapshot_path="/var/lib/lxcsnaps/$LXC_NAME/snap0"
|
||||||
if [ $(sudo lxc-info --name $LXC_NAME | grep -c "STOPPED") -eq 0 ]; then
|
|
||||||
echo "Arrêt du conteneur LXC" | tee -a "$RESULT"
|
# Stop the LXC container
|
||||||
sudo lxc-stop -n $LXC_NAME | tee -a "$RESULT" 2>&1
|
if is_lxc_running; then
|
||||||
fi
|
echo "Stop the LXC container" | tee --append "$test_result"
|
||||||
# Restaure le snapshot.
|
sudo lxc-stop --name=$LXC_NAME | tee --append "$test_result" 2>&1
|
||||||
echo "Restauration du snapshot de la machine lxc" | tee -a "$RESULT"
|
|
||||||
if ! sudo grep -q "$LXC_NAME" /var/lib/lxcsnaps/$LXC_NAME/snap0/rootfs/etc/hosts
|
|
||||||
then # Si le nom de la machine n'est pas dans le hosts
|
|
||||||
if sudo grep -q "snap0" /var/lib/lxcsnaps/$LXC_NAME/snap0/rootfs/etc/hosts
|
|
||||||
then # Si le hosts a été remplacé par snap0 (-_-), on corrige
|
|
||||||
sudo sed -i "s/snap0/$LXC_NAME/" /var/lib/lxcsnaps/$LXC_NAME/snap0/rootfs/etc/hosts
|
|
||||||
else # Sinon ajoute simplement une ligne dans le hosts
|
|
||||||
echo "$LXC_NAME" | sudo tee -a /var/lib/lxcsnaps/$LXC_NAME/snap0/rootfs/etc/hosts > /dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
sudo rsync -aEAX --delete -i /var/lib/lxcsnaps/$LXC_NAME/snap0/rootfs/ /var/lib/lxc/$LXC_NAME/rootfs/ > /dev/null 2>> "$RESULT"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Fix the missing hostname in the hosts file
|
||||||
|
# If the hostname is missing in /etc/hosts inside the snapshot
|
||||||
|
if ! sudo grep --quiet "$LXC_NAME" "$snapshot_path/rootfs/etc/hosts"
|
||||||
|
then
|
||||||
|
# If the hostname was replaced by snap0, fix it
|
||||||
|
if sudo grep --quiet "snap0" "$snapshot_path/rootfs/etc/hosts"
|
||||||
|
then
|
||||||
|
# Replace snap0 by the real hostname
|
||||||
|
sudo sed --in-place "s/snap0/$LXC_NAME/" "$snapshot_path/rootfs/etc/hosts"
|
||||||
|
else
|
||||||
|
# Otherwise, simply add the hostname
|
||||||
|
echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$snapshot_path/rootfs/etc/hosts" > /dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore the snapshot.
|
||||||
|
echo "Restore the previous snapshot." | tee --append "$test_result"
|
||||||
|
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/rootfs/" "/var/lib/lxc/$LXC_NAME/rootfs/" > /dev/null 2>> "$test_result"
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_TURNOFF () {
|
LXC_TURNOFF () {
|
||||||
echo "Arrêt du réseau pour le conteneur."
|
# Deactivate LXC network
|
||||||
# Suppression des règles de parefeu
|
|
||||||
if sudo iptables -C FORWARD -i $LXC_BRIDGE -o $main_iface -j ACCEPT 2> /dev/null
|
echo "Deactivate iptables rules."
|
||||||
|
if sudo iptables --check FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT 2> /dev/null
|
||||||
then
|
then
|
||||||
sudo iptables -D FORWARD -i $LXC_BRIDGE -o $main_iface -j ACCEPT >> "$RESULT" 2>&1
|
sudo iptables --delete FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1
|
||||||
fi
|
fi
|
||||||
if sudo iptables -C FORWARD -i $main_iface -o $LXC_BRIDGE -j ACCEPT 2> /dev/null
|
if sudo iptables --check FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT 2> /dev/null
|
||||||
then
|
then
|
||||||
sudo iptables -D FORWARD -i $main_iface -o $LXC_BRIDGE -j ACCEPT | tee -a "$RESULT" 2>&1
|
sudo iptables --delete FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT | tee --append "$test_result" 2>&1
|
||||||
fi
|
fi
|
||||||
if sudo iptables -t nat -C POSTROUTING -s $PLAGE_IP.0/24 -j MASQUERADE 2> /dev/null
|
if sudo iptables --table nat --check POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE 2> /dev/null
|
||||||
then
|
then
|
||||||
sudo iptables -t nat -D POSTROUTING -s $PLAGE_IP.0/24 -j MASQUERADE | tee -a "$RESULT" 2>&1
|
sudo iptables --table nat --delete POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
|
||||||
fi
|
fi
|
||||||
# Et arrêt du bridge
|
|
||||||
|
echo "Deactivate the network bridge."
|
||||||
if sudo ifquery $LXC_BRIDGE --state > /dev/null
|
if sudo ifquery $LXC_BRIDGE --state > /dev/null
|
||||||
then
|
then
|
||||||
sudo ifdown --force $LXC_BRIDGE | tee -a "$RESULT" 2>&1
|
sudo ifdown --force $LXC_BRIDGE | tee --append "$test_result" 2>&1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_CONNECT_INFO () {
|
LXC_CONNECT_INFO () {
|
||||||
echo "> Connexion au conteneur:"
|
# Print access information
|
||||||
echo "Pour exécuter une seule commande:"
|
|
||||||
echo -e "\e[1msudo lxc-attach -n $LXC_NAME -- commande\e[0m"
|
|
||||||
|
|
||||||
echo "Pour établir une connexion ssh:"
|
echo "> For access the container:"
|
||||||
|
echo "To execute one command:"
|
||||||
|
echo -e "\e[1msudo lxc-attach -n $LXC_NAME -- command\e[0m"
|
||||||
|
|
||||||
|
echo "To establish a ssh connection:"
|
||||||
if [ $(cat "$script_dir/setup_user") = "root" ]; then
|
if [ $(cat "$script_dir/setup_user") = "root" ]; then
|
||||||
echo -ne "\e[1msudo "
|
echo -ne "\e[1msudo "
|
||||||
fi
|
fi
|
||||||
echo -e "\e[1mssh $ARG_SSH $LXC_NAME\e[0m"
|
echo -e "\e[1mssh $arg_ssh $LXC_NAME\e[0m"
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue