From 884cd649758f026c9a467ec332c371050841acb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sat, 20 Jan 2024 10:27:18 -0300 Subject: [PATCH] core: start-blueos-core: Detect critical disk space and try to recover MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- core/start-blueos-core | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/start-blueos-core b/core/start-blueos-core index b3f598d6ed..686b6c1206 100755 --- a/core/start-blueos-core +++ b/core/start-blueos-core @@ -15,6 +15,9 @@ MAV_COMPONENT_ID_ONBOARD_COMPUTER4=194 # Enable Rust backtrace for all programs RUST_BACKTRACE=1 +# Set BlueOS log folder +BLUEOS_LOG_FOLDER_PATH="/var/logs/blueos" + # Update docker binds, if we need to restart, exit! blueos_startup_update @@ -62,6 +65,18 @@ else echo "Waring: Using dockers's resolv.conf, this may cause DNS issues if the host's network configuration changes." fi +# The system may start with full disk, in this case resulting in an unstable behavior. +# As an attempt to recover the system, lets delete the log files before current boot +AVAILABLE_SPACE_MB=$(($(stat -f / --format="%a*%S/1024**2"))) +CRITICAL_SPACE_LIMIT_MB=100 +(( AVAILABLE_SPACE_MB < CRITICAL_SPACE_LIMIT_MB )) && ( + LOG_FOLDER_SIZE=$(($(du -sm ${BLUEOS_LOG_FOLDER_PATH} | awk '{print $1}'))) + echo "Not enough free space for the system to run: ${AVAILABLE_SPACE_MB}MB" + echo "Going to delete the logs folder as an attempt to recover: ${LOG_FOLDER_SIZE}MB" + rm -rf "$BLUEOS_LOG_FOLDER_PATH" + echo "Done!" +) + # These services have priority because they do the fundamental for the vehicle to work, # and by initializing them first we reduce the time users have to wait to control the vehicle. # From tests with QGC and Pi3, the reboot time was ~1min42s when not using this strategy, @@ -112,7 +127,7 @@ function create_service { fi # Set all necessary environment variables for the new tmux session - for NAME in $(compgen -v | grep MAV_); do + for NAME in $(compgen -v | grep -e MAV_ -e BLUEOS_); do VALUE=${!NAME} tmux setenv -t $SESSION_NAME -g $NAME $VALUE done