From cb528de152c6ed4df040278405a1e18ef9211cb0 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 22:01:48 -0700 Subject: [PATCH] Move archiveloop.log to /mutable, and add primitive log rotation. --- run/archiveloop | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/run/archiveloop b/run/archiveloop index a5890a4..23b5b31 100644 --- a/run/archiveloop +++ b/run/archiveloop @@ -1,7 +1,7 @@ #!/bin/bash -eu ARCHIVE_HOST_NAME="$1" -export LOG_FILE=/tmp/archiveloop.log +export LOG_FILE=/mutable/archiveloop.log export CAM_MOUNT=/mnt/cam export MUSIC_MOUNT=/mnt/music @@ -232,6 +232,17 @@ function archive_clips () { fi } +function truncate_log () { + local 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 +} + export -f mount_mountpoint export -f ensure_mountpoint_is_mounted export -f retry @@ -260,5 +271,7 @@ do archive_clips + truncate_log + wait_for_archive_to_be_unreachable done