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.
local max_try=3
local i=0
for i in `seq 1 $max_try`
while [ $i -lt $max_try ]
do
i=$(( $i +1 ))
# 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
if ! is_lxc_running; then
@ -165,9 +166,9 @@ LXC_START () {
local avoid_witness=1
fi
# Check during 20 seconds if the container has finished to start.
# Try to connect 5 times
local j=0
for j in `seq 1 20`
for j in `seq 1 5`
do
echo -n .
# 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 message="The container failed to start $max_try times on $ci_path.
$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
# 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
dest=$(grep '\"dest\": ' "$script_dir/../config" | cut -d= -f2)
dest=$(grep 'dest=' "$script_dir/../config" | cut -d= -f2)
mail -s "$subject" "$dest" <<< "$message"
fi
}
@ -230,36 +236,39 @@ $lxc_check_result
ECHO_FORMAT "The container failed to start $max_try times...\n" "red" "bold"
ECHO_FORMAT "Boot log:\n" clog
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"
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
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"
send_email
i=0
continue
elif [ $lxc_check -eq 1 ]; then
local lxc_check_result="An error has happened with the host. Please check the configuration."
ECHO_FORMAT "$lxc_check_result\n" "red" "bold"
send_email
stop_timer 1
return 1
elif [ $lxc_check -eq 2 ]; then
local lxc_check_result="The container is broken, it will be rebuilt."
ECHO_FORMAT "$lxc_check_result\n" "red" "bold"
$script_dir/sub_scripts/lxc_build.sh
LXC_INIT
send_email
i=0
continue
elif [ $lxc_check -eq 3 ]; then
local lxc_check_result="The container has been fixed by lxc_check."
ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold"
send_email
i=0
continue
fi
fi
done
stop_timer 1
start_timer
# Count the number of lines of the current yunohost log file.
COPY_LOG 1

View file

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