Fix errors.

This commit is contained in:
cimryan
2018-10-22 21:48:27 -07:00
parent 1916470ec8
commit 71612c46ef

View File

@@ -3,14 +3,14 @@
# Change the value on the right side of the equal sign to the name of the server hosting the archive. # Change the value on the right side of the equal sign to the name of the server hosting the archive.
ARCHIVE_HOST_NAME=archiveserver ARCHIVE_HOST_NAME=archiveserver
LOGFILE=/tmp/archiveloop.log LOG_FILE=/tmp/archiveloop.log
export CAM_MOUNT=/mnt/cam export CAM_MOUNT=/mnt/cam
export MUSIC_MOUNT=/mnt/music export MUSIC_MOUNT=/mnt/music
function log () { function log () {
echo "$( date )" >> "$LOGFILE" echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOGFILE" echo "$1" >> "$LOG_FILE"
} }
function fix_errors_in_mount_point () { function fix_errors_in_mount_point () {
@@ -51,6 +51,12 @@ function wait_for_archive_to_be_reachable () {
log "Archive is reachable." log "Archive is reachable."
break break
fi fi
if [ -e /tmp/archive_is_reachable ]
then
log "Simulating archive is reachable"
rm /tmp/archive_is_reachable
break
fi
sleep 1 sleep 1
done done
} }
@@ -116,9 +122,7 @@ function ensure_mountpoint_is_mounted_with_retry () {
} }
function fix_errors_in_cam_file () { function fix_errors_in_cam_file () {
ensure_cam_file_is_mounted
fix_errors_in_mount_point "$CAM_MOUNT" fix_errors_in_mount_point "$CAM_MOUNT"
unmount_cam_file
} }
function ensure_cam_file_is_mounted () { function ensure_cam_file_is_mounted () {
@@ -136,7 +140,7 @@ function ensure_music_file_is_mounted () {
function unmount_mount_point () { function unmount_mount_point () {
local mount_point="$1" local mount_point="$1"
log "Unmounting $mount_point..." log "Unmounting $mount_point..."
umount "$mount_point" umount "$mount_point" >> "$LOG_FILE" 2>&1
log "Unmounted $mount_point." log "Unmounted $mount_point."
} }
@@ -149,9 +153,7 @@ function unmount_music_file () {
} }
function fix_errors_in_music_file () { function fix_errors_in_music_file () {
ensure_music_file_is_mounted
fix_errors_in_mount_point "$MUSIC_MOUNT" fix_errors_in_mount_point "$MUSIC_MOUNT"
unmount_music_file
} }
function archive_clips () { function archive_clips () {
@@ -169,15 +171,34 @@ function wait_for_archive_to_be_unreachable () {
log "Archive is unreachable." log "Archive is unreachable."
break break
fi fi
if [ -e /tmp/archive_is_unreachable ]
then
log "Simulating archive being unreachable."
rm /tmp/archive_is_unreachable
break
fi
sleep 1 sleep 1
done done
} }
function fix_errors_in_files () { function mount_and_fix_errors_in_cam_file () {
ensure_cam_file_is_mounted
fix_errors_in_cam_file fix_errors_in_cam_file
fix_errors_in_music_file unmount_cam_file
} }
function mount_and_fix_errors_in_music_file () {
ensure_music_file_is_mounted
fix_errors_in_music_file
unmount_music_file
}
function mount_and_fix_errors_in_files () {
mount_and_fix_errors_in_cam_file
mount_and_fix_errors_in_music_file
}
export -f fix_errors_in_mount_point
export -f fix_errors_in_cam_file export -f fix_errors_in_cam_file
export -f retry export -f retry
export -f mount_mountpoint export -f mount_mountpoint
@@ -185,6 +206,7 @@ export -f ensure_mountpoint_is_mounted
export -f ensure_mountpoint_is_mounted_with_retry export -f ensure_mountpoint_is_mounted_with_retry
export -f ensure_cam_file_is_mounted export -f ensure_cam_file_is_mounted
export -f fix_errors_in_cam_file export -f fix_errors_in_cam_file
export -f unmount_mount_point
export -f unmount_cam_file export -f unmount_cam_file
export -f connect_usb_drives_to_host export -f connect_usb_drives_to_host
@@ -193,13 +215,13 @@ log "Starting..."
if archive_is_reachable if archive_is_reachable
then then
# archive_clips will fix errors in the cam file # archive_clips will fix errors in the cam file
fix_errors_in_music_file mount_and_fix_errors_in_music_file
archive_clips archive_clips
wait_for_archive_to_be_unreachable wait_for_archive_to_be_unreachable
else else
fix_errors_in_files mount_and_fix_errors_in_files
connect_usb_drives_to_host connect_usb_drives_to_host
fi fi