From ab4a348a26072a94dd78ab52b4281a18f17e37d4 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Sat, 3 Oct 2020 05:43:31 -0500 Subject: [PATCH] fix(plg): revamp rc.flash_backup script --- dynamix.unraid.net.plg | 82 +++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/dynamix.unraid.net.plg b/dynamix.unraid.net.plg index 821f3d6a7..a51467295 100644 --- a/dynamix.unraid.net.plg +++ b/dynamix.unraid.net.plg @@ -593,29 +593,79 @@ response_complete($httpcode, $result, 'success'); - + /dev/null + # start watcher loop as background process + _watch &>/dev/null & + exit 0 +} +stop() { + # terminate watcher loop/process + pkill --full "${INOTIFY}" &>/dev/null + # remove any queued jobs + _removequeue + exit 0 +} +reload() { + stop + sleep 1 + start + sleep 1 + status + exit 0 +} +_watch() { + # start inotify watcher loop + ${INOTIFY} | + while read path action file; do + _removequeue -# delete any at jobs in queue f -atq ${QUEUE} | while read line; do - id=`echo ${line} | cut -d " " -f 1` - atrm ${id} -done + logger '/boot changes detected, (re)starting 1 min countdown before backing up' --tag flash_backup -# create a new at job in queue f -echo "php /usr/local/emhttp/plugins/dynamix.unraid.net/include/UpdateFlashBackup.php update" | at ${QUEUE} now +1 minute + # create a new at job in queue f + echo "php /usr/local/emhttp/plugins/dynamix.unraid.net/include/UpdateFlashBackup.php update" | at ${QUEUE} now +1 minute + done +} +_removequeue() { + # delete any at jobs in queue f + atq ${QUEUE} | while read line; do + id=`echo ${line} | cut -d " " -f 1` + atrm ${id} + done +} +case "$1" in +'status') + status + ;; +'start') + start + ;; +'stop') + stop true + ;; +'reload') + reload + ;; +*) + echo "usage $0 status|start|stop|reload" +esac ]]>