Various fixes for auto repair feature

This commit is contained in:
Maniack Crudelis 2018-10-17 22:28:32 +02:00
parent e3e1cda79c
commit 55143ec9f4
2 changed files with 27 additions and 18 deletions

View file

@ -152,8 +152,9 @@ LXC_START () {
# Try to start the container 3 times. # Try to start the container 3 times.
local max_try=3 local max_try=3
local i=0 local i=0
for i in `seq 1 $max_try` while [ $i -lt $max_try ]
do do
i=$(( $i +1 ))
# Start the container and log the booting process in $script_dir/lxc_boot.log # Start the container and log the booting process in $script_dir/lxc_boot.log
# Try to start only if the container is not already started # Try to start only if the container is not already started
if ! is_lxc_running; then if ! is_lxc_running; then
@ -165,9 +166,9 @@ LXC_START () {
local avoid_witness=1 local avoid_witness=1
fi fi
# Check during 20 seconds if the container has finished to start. # Try to connect 5 times
local j=0 local j=0
for j in `seq 1 20` for j in `seq 1 5`
do do
echo -n . echo -n .
# Try to connect with ssh to check if the container is ready to work. # Try to connect with ssh to check if the container is ready to work.
@ -216,13 +217,18 @@ LXC_START () {
local subject="[YunoHost] Container in trouble on $ci_path." local subject="[YunoHost] Container in trouble on $ci_path."
local message="The container failed to start $max_try times on $ci_path. local message="The container failed to start $max_try times on $ci_path.
$lxc_check_result $lxc_check_result
\n\nPlease have a look to the log of lxc_check:\n$(cat "$script_dir/lxc_check.log")"
Please have a look to the log of lxc_check:
$(cat "$script_dir/lxc_check.log")"
if [ $lxc_check -eq 2 ]; then if [ $lxc_check -eq 2 ]; then
# Add the log of lxc_build # Add the log of lxc_build
message="\nHere the log of lxc_build:\n$(cat "$script_dir/sub_scripts/Build_lxc.log")" message="$message
Here the log of lxc_build:
$(cat "$script_dir/sub_scripts/Build_lxc.log")"
fi fi
dest=$(grep '\"dest\": ' "$script_dir/../config" | cut -d= -f2) dest=$(grep 'dest=' "$script_dir/../config" | cut -d= -f2)
mail -s "$subject" "$dest" <<< "$message" mail -s "$subject" "$dest" <<< "$message"
fi fi
} }
@ -230,36 +236,39 @@ $lxc_check_result
ECHO_FORMAT "The container failed to start $max_try times...\n" "red" "bold" ECHO_FORMAT "The container failed to start $max_try times...\n" "red" "bold"
ECHO_FORMAT "Boot log:\n" clog ECHO_FORMAT "Boot log:\n" clog
cat "$script_dir/lxc_boot.log" | tee --append "$test_result" cat "$script_dir/lxc_boot.log" | tee --append "$test_result"
stop_timer 1
ECHO_FORMAT "lxc_check will try to fix the container...\n" "red" "bold" ECHO_FORMAT "lxc_check will try to fix the container...\n" "red" "bold"
local lxc_check="$($script_dir/sub_scripts/lxc_check.sh --no-lock >&2 | tee "$script_dir/lxc_check.log")" $script_dir/sub_scripts/lxc_check.sh --no-lock | tee "$script_dir/lxc_check.log"
# PIPESTATUS is an array with the exit code of each command followed by a pipe
local lxc_check=${PIPESTATUS[0]}
LXC_INIT
if [ $lxc_check -eq 0 ]; then if [ $lxc_check -eq 0 ]; then
local lxc_check_result="But the container seems to be ok, according to lxc_check." local lxc_check_result="The container seems to be ok, according to lxc_check."
ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold" ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold"
send_email send_email
i=0 i=0
continue
elif [ $lxc_check -eq 1 ]; then elif [ $lxc_check -eq 1 ]; then
local lxc_check_result="An error has happened with the host. Please check the configuration." local lxc_check_result="An error has happened with the host. Please check the configuration."
ECHO_FORMAT "$lxc_check_result\n" "red" "bold" ECHO_FORMAT "$lxc_check_result\n" "red" "bold"
send_email send_email
stop_timer 1
return 1 return 1
elif [ $lxc_check -eq 2 ]; then elif [ $lxc_check -eq 2 ]; then
local lxc_check_result="The container is broken, it will be rebuilt." local lxc_check_result="The container is broken, it will be rebuilt."
ECHO_FORMAT "$lxc_check_result\n" "red" "bold" ECHO_FORMAT "$lxc_check_result\n" "red" "bold"
$script_dir/sub_scripts/lxc_build.sh $script_dir/sub_scripts/lxc_build.sh
LXC_INIT
send_email send_email
i=0 i=0
continue
elif [ $lxc_check -eq 3 ]; then elif [ $lxc_check -eq 3 ]; then
local lxc_check_result="The container has been fixed by lxc_check." local lxc_check_result="The container has been fixed by lxc_check."
ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold" ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold"
send_email send_email
i=0 i=0
continue
fi fi
fi fi
done done
stop_timer 1
start_timer
# Count the number of lines of the current yunohost log file. # Count the number of lines of the current yunohost log file.
COPY_LOG 1 COPY_LOG 1

View file

@ -284,8 +284,8 @@ check_repair=0
echo -e "\e[1m> Test de la configuration réseau du côté de l'hôte:\e[0m" echo -e "\e[1m> Test de la configuration réseau du côté de l'hôte:\e[0m"
CREATE_BRIDGE () { CREATE_BRIDGE () {
echo | sudo tee /etc/network/interfaces.d/$LXC_BRIDGE <<EOF echo | sudo tee /etc/network/interfaces.d/$LXC_BRIDGE <<EOF
auto $LXC_BRIDGE auto $LXC_BRIDGE
iface $LXC_BRIDGE inet static iface $LXC_BRIDGE inet static
address $PLAGE_IP.1/24 address $PLAGE_IP.1/24
bridge_ports none bridge_ports none
bridge_fd 0 bridge_fd 0