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.
This commit is contained in:
cimryan
2018-10-13 08:11:02 -07:00
parent 64b323eb76
commit 499d23cb36

View File

@@ -7,6 +7,30 @@ function log () {
echo "$1" >> "$LOGFILE" 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 () { function mount_mountpoint () {
local mount_point="$1" local mount_point="$1"
log "Mounting $mount_point..." log "Mounting $mount_point..."
@@ -39,6 +63,10 @@ function ensure_mountpoint_is_mounted () {
fi fi
} }
function ensure_mountpoint_is_mounted_with_retry () {
retry ensure_mountpoint_is_mounted "$1"
}
function move_clips_to_archive () { function move_clips_to_archive () {
log "Moving clips to archive..." log "Moving clips to archive..."
for file_name in /mnt/usb_share/TeslaCam/saved*; do 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 () { function ensure_cam_archive_is_mounted () {
log "Ensuring 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." log "Ensured cam archive is mounted."
} }
function ensure_usb_share_is_mounted () { function ensure_usb_share_is_mounted () {
log "Ensuring 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." log "Ensured usb share is mounted."
} }