From 98b5e893f83cb37a5eee9f11ea46d00bd1cb1eca 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 1/2] 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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/start-blueos-core b/core/start-blueos-core index b3f598d6ed..4917cf57d7 100755 --- a/core/start-blueos-core +++ b/core/start-blueos-core @@ -15,6 +15,22 @@ 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" + +# 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 +echo "Available disk space: ${AVAILABLE_SPACE_MB}MB" +(( 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, limit is: ${CRITICAL_SPACE_LIMIT_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!" +) + # Update docker binds, if we need to restart, exit! blueos_startup_update @@ -112,7 +128,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 From 5513a47dc89b5a452dad2c1cf36f72b0715f0ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sat, 20 Jan 2024 10:27:44 -0300 Subject: [PATCH 2/2] core: services: commander: main: Use global BLUEOS_LOG_FOLDER_PATH over hardcoded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- core/services/commander/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services/commander/main.py b/core/services/commander/main.py index 7f6d813f9d..7340473295 100755 --- a/core/services/commander/main.py +++ b/core/services/commander/main.py @@ -20,7 +20,7 @@ from loguru import logger SERVICE_NAME = "commander" -LOG_FOLDER_PATH = "/var/logs/blueos" +LOG_FOLDER_PATH = os.environ.get("BLUEOS_LOG_FOLDER_PATH", "/var/logs/blueos") limit_ram_usage()