Code based on mv

This commit is contained in:
Alexandre
2024-10-07 14:52:33 +02:00
committed by GitHub
parent b357a56f4a
commit 98061be4a1

View File

@@ -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