Avoid connecting the USB drive if it'll just immediately be disconnected.

This commit is contained in:
cimryan
2018-10-12 13:44:18 -07:00
parent 24d662276e
commit 1aac431c06
3 changed files with 28 additions and 21 deletions

View File

@@ -44,7 +44,7 @@ function move_clips_to_archive () {
for file_name in /mnt/usb_share/TeslaCam/saved*; do for file_name in /mnt/usb_share/TeslaCam/saved*; do
[ -e "$file_name" ] || continue [ -e "$file_name" ] || continue
log "Moving $file_name ..." log "Moving $file_name ..."
mv -- "$file_name" /mnt/cam_archive >> "$LOGFILE" 2>&1 mv -- "$file_name" /mnt/cam_archive >> "$LOGFILE" 2>&1 || echo ""
log "Moved $file_name." log "Moved $file_name."
done done
log "Finished moving clips to archive." log "Finished moving clips to archive."
@@ -56,6 +56,12 @@ function disconnect_usb_from_host () {
log "Disconnected usb from host." log "Disconnected usb from host."
} }
function fix_errors_on_drive () {
log "Running fsck..."
/sbin/fsck /mnt/usb_share -- -a >> "$LOGFILE" 2>&1 || echo ""
log "Finished running fsck."
}
function mount_usb_drive_locally () { function mount_usb_drive_locally () {
log "Mounting usb locally..." log "Mounting usb locally..."
mount /mnt/usb_share mount /mnt/usb_share
@@ -80,18 +86,14 @@ function unmount_usb_share () {
log "Unmounted usb share." log "Unmounted usb share."
} }
function connect_usb_to_host() {
log "Connecting usb to host..."
modprobe g_mass_storage
log "Connected usb to host."
}
log "Starting..." log "Starting..."
ensure_cam_archive_is_mounted ensure_cam_archive_is_mounted
disconnect_usb_from_host disconnect_usb_from_host
fix_errors_on_drive
ensure_usb_share_is_mounted ensure_usb_share_is_mounted
move_clips_to_archive move_clips_to_archive

View File

@@ -4,16 +4,12 @@
ARCHIVE_HOST_NAME=archiveserver ARCHIVE_HOST_NAME=archiveserver
LOGFILE=/tmp/archiveloop.log LOGFILE=/tmp/archiveloop.log
function clear_log () {
rm "$LOGFILE" > /dev/null 2>&1 || echo ""
}
function log () { function log () {
echo "$( date )" >> "$LOGFILE" echo "$( date )" >> "$LOGFILE"
echo "$1" >> "$LOGFILE" echo "$1" >> "$LOGFILE"
} }
function check_archive_reachability () { function archive_is_reachable () {
local reachable=true local reachable=true
ping -q -w 1 -c 1 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false ping -q -w 1 -c 1 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false
if [ "$reachable" = false ] if [ "$reachable" = false ]
@@ -24,11 +20,17 @@ function check_archive_reachability () {
true true
} }
function connect_usb_to_host() {
log "Connecting usb to host..."
modprobe g_mass_storage
log "Connected usb to host."
}
function wait_for_archive_to_be_reachable () { function wait_for_archive_to_be_reachable () {
log "Waiting for archive to be reachable..." log "Waiting for archive to be reachable..."
while [ true ] while [ true ]
do do
if check_archive_reachability if archive_is_reachable
then then
log "Archive is reachable." log "Archive is reachable."
break break
@@ -47,7 +49,7 @@ function wait_for_archive_to_be_unreachable () {
log "Waiting for archive to be unreachable..." log "Waiting for archive to be unreachable..."
while [ true ] while [ true ]
do do
if ! check_archive_reachability if ! archive_is_reachable
then then
log "Archive is unreachable." log "Archive is unreachable."
break break
@@ -56,10 +58,17 @@ function wait_for_archive_to_be_unreachable () {
done done
} }
clear_log export -f connect_usb_to_host
log "Starting..." log "Starting..."
if archive_is_reachable
then
archive_clips
else
connect_usb_to_host
fi
while [ true ] while [ true ]
do do
wait_for_archive_to_be_reachable wait_for_archive_to_be_reachable

View File

@@ -73,10 +73,6 @@ function log () {
echo "$1" >> "$LOGFILE" echo "$1" >> "$LOGFILE"
} }
log "Running fsck..."
/sbin/fsck /mnt/usb_share -- -a >> "$LOGFILE" 2>&1 || echo ""
log "Running modprobe..."
/sbin/modprobe g_mass_storage >> "$LOGFILE" 2>&1
log "Launching archival script..." log "Launching archival script..."
/root/bin/archiveloop & /root/bin/archiveloop &
log "All done" log "All done"