From 98061be4a112cdfdc9a8cae8fe13ba198a770ddc Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:52:33 +0200 Subject: [PATCH] Code based on mv --- .../etc/cont-finish.d/savestreamdata.sh | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh b/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh index c92765c6d..de9eaae80 100755 --- a/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh +++ b/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh @@ -2,19 +2,34 @@ # shellcheck shell=bash if [ -d "$HOME"/BirdSongs/StreamData ]; then - bashio::log.fatal "Container stopping, saving temporary files" + bashio::log.fatal "Container stopping, saving temporary files." # Stop the services in parallel - systemctl stop birdnet_analysis & - systemctl stop birdnet_recording - - # Ensure the target directory exists - mkdir -p /data/StreamData - - # Use rsync to move files to /data/StreamData - if [ "$(ls -A "$HOME"/BirdSongs/StreamData)" ]; then - rsync -av --remove-source-files "$HOME"/BirdSongs/StreamData/ /data/StreamData/ + if systemctl is-active --quiet birdnet_analysis; then + bashio::log.info "Stopping birdnet_analysis service." + systemctl stop birdnet_analysis & fi - bashio::log.fatal "... files safe, allowing container to stop" + if systemctl is-active --quiet birdnet_recording; then + bashio::log.info "Stopping birdnet_recording service." + systemctl stop birdnet_recording & + fi + + # Wait for both services to stop + wait + + # Check if there are files in StreamData and move them to /data/StreamData + mkdir -p /data/StreamData + if [ "$(ls -A "$HOME"/BirdSongs/StreamData)" ]; then + if mv -v "$HOME"/BirdSongs/StreamData/* /data/StreamData/; then + bashio::log.info "Files successfully moved to /data/StreamData." + else + bashio::log.error "Failed to move files to /data/StreamData." + exit 1 + fi + fi + + bashio::log.info "... files safe, allowing container to stop." +else + bashio::log.info "No StreamData directory to process." fi