Skip to content

Commit

Permalink
core: start-blueos-core: Detect critical disk space and try to recover
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Jan 20, 2024
1 parent e3782b7 commit 884cd64
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/start-blueos-core
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 884cd64

Please sign in to comment.