From 499d23cb36462d1d96b8190b64603ad82389903d Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 13 Oct 2018 08:11:02 -0700 Subject: [PATCH] Retry mounting the shares up to 10 times. There's a race between the system mounting the share and the findmnt invocation in the script to determine if the share is already mounted. When findmnt wins the race the script would previously operate as if the share definitely needed to be mounted, and would fail to mount it. Now the script will notice that the share has already been mounted. --- windows_archive/archive-teslacam-clips | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 69d4dde..fa83ef8 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -7,6 +7,30 @@ function log () { echo "$1" >> "$LOGFILE" } +function retry () { + local attempts=0 + while [ true ] + do + if eval "$@" + then + true + return + fi + if [ "$attempts" -ge 10 ] + then + log "Attempts exhausted." + false + return + fi + log "Sleeping before retry..." + /bin/sleep 1 + attempts=$((attempts + 1)) + log "Retrying..." + done + false + return +} + function mount_mountpoint () { local mount_point="$1" log "Mounting $mount_point..." @@ -39,6 +63,10 @@ function ensure_mountpoint_is_mounted () { fi } +function ensure_mountpoint_is_mounted_with_retry () { + retry ensure_mountpoint_is_mounted "$1" +} + function move_clips_to_archive () { log "Moving clips to archive..." for file_name in /mnt/usb_share/TeslaCam/saved*; do @@ -70,13 +98,13 @@ function mount_usb_drive_locally () { function ensure_cam_archive_is_mounted () { log "Ensuring cam archive is mounted..." - ensure_mountpoint_is_mounted /mnt/cam_archive + ensure_mountpoint_is_mounted_with_retry /mnt/cam_archive log "Ensured cam archive is mounted." } function ensure_usb_share_is_mounted () { log "Ensuring usb share is mounted..." - ensure_mountpoint_is_mounted /mnt/usb_share + ensure_mountpoint_is_mounted_with_retry /mnt/usb_share log "Ensured usb share is mounted." }