Skip to content

Commit

Permalink
Change log truncation
Browse files Browse the repository at this point in the history
Instead of truncating the log only after archiving, truncate it whenever
it gets above 1M bytes. This prevents the log from growing out of control
if TeslaUSB is configured to not do any archiving, or if archiving never
completes for some reason.
  • Loading branch information
marcone committed Dec 16, 2024
1 parent 05cf0e6 commit 996bfc3
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions run/archiveloop
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ modprobe -r g_ether
export LOG_FILE=/mutable/archiveloop.log

function log () {
echo -n "$( date ): " >> "$LOG_FILE"
echo "$@" >> "$LOG_FILE"
echo "$( date ):" "$@" >> "$LOG_FILE"
if [[ "$(stat --format="%s" "$LOG_FILE")" -gt 1000000 ]]
then
local log_file2="${LOG_FILE}.2"
tail -n 5000 "$LOG_FILE" > "${log_file2}"
mv "$log_file2" "$LOG_FILE"
log "(log truncated)"
fi
}

function log_errors_on_exit {
Expand Down Expand Up @@ -664,18 +670,6 @@ function archive_clips () {
/root/bin/disconnect-archive.sh
}

function truncate_log () {
local log_length
log_length=$( wc -l "$LOG_FILE" | cut -d' ' -f 1 )
if [ "$log_length" -gt 10000 ]
then
log "Truncating log..."
local log_file2="${LOG_FILE}.2"
tail -n 10000 "$LOG_FILE" > "${LOG_FILE}.2"
mv "$log_file2" "$LOG_FILE"
fi
}

function slowblink () {
echo timer > "$STATUSLED/trigger" || return 0
echo 900 > "$STATUSLED/delay_off"
Expand Down Expand Up @@ -886,8 +880,6 @@ do

archive_clips

truncate_log

/root/bin/awake_stop || true

doubleblink
Expand Down

0 comments on commit 996bfc3

Please sign in to comment.