diff --git a/plugins/mvd.lua b/plugins/mvd.lua index 8bdb6f4..adc10e6 100644 --- a/plugins/mvd.lua +++ b/plugins/mvd.lua @@ -127,7 +127,8 @@ end function mvd_os_exec(script) gi.dprintf('mvd.lua mvd_os_exec(): '..script..'\n') - local returnstuff = os.execute(script) + local cmd = string.format('nohup %s > script.log 2>&1 &', script) + local returnstuff = os.execute(cmd) gi.dprintf('mvd.lua mvd_os_exec(): returns: '..returnstuff..'\n') return returnstuff end diff --git a/plugins/mvd_transfer.sh b/plugins/mvd_transfer.sh index e0988d8..7e8f81f 100755 --- a/plugins/mvd_transfer.sh +++ b/plugins/mvd_transfer.sh @@ -26,16 +26,36 @@ _rsakeylocation="$HOME/.ssh/id_rsa" ## AQTion MVD transfer -if [ -f "${_fullfilepath}" ]; then - ( sleep 10 ) && ( s3cmd put "${_fullfilepath}" s3://${_s3bucket}/${_targetdir}/${_servertargetdir}/${_file} ) & -elif [ -z "${_file}" ]; then - echo "$0 Error: $_file not found. Not transferring anything. :(" - exit 1 -else - echo "Something went wrong other than file not found" +max_retries=5 +retries=0 + +while [ $retries -lt $max_retries ]; do + if [ -f "${_fullfilepath}" ]; then + if lsof "${_fullfilepath}" > /dev/null; then + echo "Error: ${_file} is open or being written to by another process. Not transferring." + exit 1 + else + ( sleep 5 ) && ( s3cmd put "${_fullfilepath}" s3://${_s3bucket}/${_targetdir}/${_servertargetdir}/${_file} ) && break + fi + elif [ -z "${_file}" ]; then + echo "$0 Error: ${_file} not found. Not transferring anything. :(" + exit 1 + else + echo "Something went wrong other than file not found" + exit 1 + fi + + retries=$((retries+1)) + echo "Upload failed (retry $retries of $max_retries). Retrying in 2 seconds..." + sleep 2 +done + +if [ $retries -eq $max_retries ]; then + echo "Max retries reached for ${_file}. Upload failed after $max_retries attempts. Exiting." exit 1 fi + ## Old method, keeping around but unused: # if [ -f "${_filepath}/${_file}" ]; then