diff --git a/package_check.sh b/package_check.sh index f5016a1..7da2a9a 100755 --- a/package_check.sh +++ b/package_check.sh @@ -177,6 +177,26 @@ fi # Create the lock file touch "$lock_file" +#================================================= +# Check the internet connectivity +#================================================= + +# Try to ping yunohost.org +ping -q -c 2 yunohost.org > /dev/null 2>&1 +if [ "$?" -ne 0 ]; then + # If fail, try to ping another domain + ping -q -c 2 framasoft.org > /dev/null 2>&1 + if [ "$?" -ne 0 ]; then + # If ping failed twice, it's seems the internet connection is down. + echo "\e[91mUnable to connect to internet.\e[0m" + + # Remove the lock file + rm -f "$lock_file" + # And exit + exit 1 + fi +fi + #================================================= # Upgrade Package check #================================================= @@ -328,26 +348,6 @@ else echo -e "\e[93mUnable to define the user who authorised to use package check. Please fill the file $setup_user_file\e[0m" fi -#================================================= -# Check the internet connectivity -#================================================= - -# Try to ping yunohost.org -ping -q -c 2 yunohost.org > /dev/null 2>&1 -if [ "$?" -ne 0 ]; then - # If fail, try to ping another domain - ping -q -c 2 framasoft.org > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - # If ping failed twice, it's seems the internet connection is down. - echo "\e[91mUnable to connect to internet.\e[0m" - - # Remove the lock file - rm -f "$lock_file" - # And exit - exit 1 - fi -fi - #================================================= # Define globals variables #================================================= @@ -682,6 +682,14 @@ TEST_RESULTS () { fi done + # If some witness files was missing, it's a big error ! So, the level fall immediately at 0. + if [ $RESULT_witness -eq 1 ] + then + ECHO_FORMAT "Some witness files has been deleted during those tests ! It's a very bad thing !\n" "red" "bold" + global_level=0 + fi + + # Then, print the levels # Print the global level ECHO_FORMAT "Level of this application: $global_level\n" "white" "bold" @@ -731,6 +739,7 @@ LXC_INIT # Default values for check_process and TESTING_PROCESS initialize_values() { # Test results + RESULT_witness=0 RESULT_linter=0 RESULT_global_setup=0 RESULT_global_remove=0 diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index cff0719..9885d9a 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -42,8 +42,10 @@ LXC_START () { if ! is_lxc_running; then echo -n "Start the LXC container" | tee --append "$test_result" sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 + local avoid_witness=0 else echo -n "A LXC container is already running" | tee --append "$test_result" + local avoid_witness=1 fi # Check during 20 seconds if the container has finished to start. @@ -79,6 +81,9 @@ LXC_START () { fi LXC_STOP # Stop the LXC container else + # Create files to check if the remove script does not remove them accidentally + [ $avoid_witness -eq 0 ] && set_witness_files + # Break the for loop if the container is ready. break fi @@ -86,7 +91,7 @@ LXC_START () { # Fail 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." "red" "bold" + ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh.\n" "red" "bold" ECHO_FORMAT "Boot log:\n" clog cat "$script_dir/lxc_boot.log" | tee --append "$test_result" return 1 diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index a7aca4f..c0a5077 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -41,6 +41,9 @@ SETUP_APP () { ECHO_FORMAT "Installation failed. ($yunohost_result)\n" "white" clog fi + # Check all the witness files, to verify if them still here + check_witness_files + # Retrieve the app id in the log. To manage the app after ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2) } @@ -65,6 +68,9 @@ REMOVE_APP () { else ECHO_FORMAT "Deleting failed. ($yunohost_remove)\n" "white" clog fi + + # Check all the witness files, to verify if them still here + check_witness_files } #================================================= @@ -474,6 +480,9 @@ CHECK_UPGRADE () { ECHO_FORMAT "Upgrade failed. ($yunohost_result)\n" "white" clog fi + # Check all the witness files, to verify if them still here + check_witness_files + # Analyse the log to extract "warning" and "error" lines LOG_EXTRACTOR @@ -916,6 +925,9 @@ CHECK_BACKUP_RESTORE () { ECHO_FORMAT "Backup failed. ($yunohost_result)\n" "white" clog fi + # Check all the witness files, to verify if them still here + check_witness_files + # Analyse the log to extract "warning" and "error" lines LOG_EXTRACTOR fi @@ -974,6 +986,9 @@ CHECK_BACKUP_RESTORE () { ECHO_FORMAT "Restore failed. ($yunohost_result)\n" "white" clog fi + # Check all the witness files, to verify if them still here + check_witness_files + # Analyse the log to extract "warning" and "error" lines LOG_EXTRACTOR @@ -1041,6 +1056,109 @@ TEST_LAUNCHER () { LXC_STOP } +set_witness_files () { + # Create files to check if the remove script does not remove them accidentally + echo -n "Create witness files" | tee --append "$test_result" + + lxc_dir="/var/lib/lxc/$lxc_name/rootfs" + + create_witness_file () { + [ "$2" = "file" ] && local action="touch" || local action="mkdir -p" + sudo $action "${lxc_dir}${1}" + } + + # Nginx conf + create_witness_file "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" file + create_witness_file "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" file + + # /etc + create_witness_file "/etc/witnessfile" file + + # /opt directory + create_witness_file "/opt/witnessdir" directory + + # /var/www directory + create_witness_file "/var/www/witnessdir" directory + + # /home/yunohost.app/ + create_witness_file "/home/yunohost.app/witnessdir" directory + + # /var/log + create_witness_file "/var/log/witnessfile" file + + # Config fpm + create_witness_file "/etc/php5/fpm/pool.d/witnessfile.conf" file + + # Config logrotate + create_witness_file "/etc/logrotate.d/witnessfile" file + + # Config systemd + create_witness_file "/etc/systemd/system/witnessfile.service" file + + # Database + for timeout in `seq 1 10` + do + sudo lxc-attach --name=$lxc_name -- mysql --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") --wait --execute="CREATE DATABASE witnessdb" > /dev/null 2>&1 && break + echo -n "." + sleep 1 + done + echo "" +} + +check_witness_files () { + # Check all the witness files, to verify if them still here + + lxc_dir="/var/lib/lxc/$lxc_name/rootfs" + + check_file_exist () { + if sudo test ! -e "${lxc_dir}${1}" + then + ECHO_FORMAT "The file $1 is missing ! Something gone wrong !\n" "red" "bold" + RESULT_witness=1 + fi + } + + # Nginx conf + check_file_exist "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" + check_file_exist "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" + + # /etc + check_file_exist "/etc/witnessfile" + + # /opt directory + check_file_exist "/opt/witnessdir" + + # /var/www directory + check_file_exist "/var/www/witnessdir" + + # /home/yunohost.app/ + check_file_exist "/home/yunohost.app/witnessdir" + + # /var/log + check_file_exist "/var/log/witnessfile" + + # Config fpm + check_file_exist "/etc/php5/fpm/pool.d/witnessfile.conf" + + # Config logrotate + check_file_exist "/etc/logrotate.d/witnessfile" + + # Config systemd + check_file_exist "/etc/systemd/system/witnessfile.service" + + # Database + if ! sudo lxc-attach --name=$lxc_name -- mysqlshow --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") | grep --quiet '^| witnessdb' > /dev/null 2>&1 + then + ECHO_FORMAT "The database witnessdb is missing ! Something gone wrong !\n" "red" "bold" + RESULT_witness=1 + fi + if [ $RESULT_witness -eq 1 ] + then + yunohost_result=1 + yunohost_remove=1 + fi +} + TESTING_PROCESS () { # Launch all tests successively