diff --git a/core/Dockerfile b/core/Dockerfile index 16606d941e..2cb2ca166e 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -79,6 +79,8 @@ COPY services /home/pi/services RUN /home/pi/services/install-services.sh COPY start-blueos-core /usr/bin/start-blueos-core COPY run-service.sh /usr/bin/run-service +RUN rm -f /etc/cron.d/* +COPY cron /etc/cron.d # Copy binaries and necessary folders from downloadBinaries to this stage COPY --from=downloadBinaries \ diff --git a/core/cron/waste-collector b/core/cron/waste-collector new file mode 100644 index 0000000000..96193d6650 --- /dev/null +++ b/core/cron/waste-collector @@ -0,0 +1 @@ +0 */4 * * * root journalctl-vacuum # Run every 4 hours \ No newline at end of file diff --git a/core/services/install-services.sh b/core/services/install-services.sh index 95c39f28a7..3a96571b73 100755 --- a/core/services/install-services.sh +++ b/core/services/install-services.sh @@ -6,13 +6,19 @@ set -e BUILD_PACKAGES=( g++ ) +EXTERNAL_PROGRAMS=( + cron +) + +apt update # Install build packages if not on armv7, which we have all pre-built wheels for if ! { [ "$TARGETARCH" == "arm" ] && [ "$TARGETVARIANT" == "v7" ]; }; then - apt update apt install -y --no-install-recommends ${BUILD_PACKAGES[*]} fi +apt install -y --no-install-recommends ${EXTERNAL_PROGRAMS[*]} + # Wifi service: ## Bind path for wpa mkdir -p /var/run/wpa_supplicant/ diff --git a/core/start-blueos-core b/core/start-blueos-core index aa6a0190ef..fd3614a873 100755 --- a/core/start-blueos-core +++ b/core/start-blueos-core @@ -93,6 +93,9 @@ mkdir -p /usr/blueos/userdata/settings find /usr/blueos -type d -exec chmod a+rw {} \; find /usr/blueos -type f -exec chmod a+rw {} \; +cron || echo "Failed to start cron service!" +journalctl-vacuum || echo "Failed to run journalctl-vacuum service!" + # 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, diff --git a/core/tools/scripts/bootstrap.sh b/core/tools/scripts/bootstrap.sh index 2b99f90386..2b69d3a6b7 100755 --- a/core/tools/scripts/bootstrap.sh +++ b/core/tools/scripts/bootstrap.sh @@ -5,3 +5,4 @@ set -e SCRIPTS_PATH="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"; cp $SCRIPTS_PATH/red-pill /usr/bin/ +cp $SCRIPTS_PATH/journalctl-vacuum /usr/bin/ diff --git a/core/tools/scripts/journalctl-vacuum b/core/tools/scripts/journalctl-vacuum new file mode 100755 index 0000000000..afac02f70c --- /dev/null +++ b/core/tools/scripts/journalctl-vacuum @@ -0,0 +1,8 @@ +#!/usr/local/bin/python +from commonwealth.utils.commands import run_command +from loguru import logger + +if __name__ == "__main__": + ret = run_command("sudo journalctl --vacuum-size=100M", False) + logger.add("/tmp/journal-vacuum.log") + logger.debug(f"Command output: {ret}")