mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
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:
@@ -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."
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user