Simplified batch runner, also less error prone
This commit is contained in:
parent
6f94429f52
commit
3f278173c1
|
@ -3,7 +3,7 @@ SUBPROGRAM=[prgname]
|
||||||
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
||||||
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
||||||
PROGRAM_BUILD=2016120101
|
PROGRAM_BUILD=2016120102
|
||||||
|
|
||||||
## Runs an osync /obackup instance for every conf file found
|
## Runs an osync /obackup instance for every conf file found
|
||||||
## If an instance fails, run it again if time permits
|
## If an instance fails, run it again if time permits
|
||||||
|
@ -66,6 +66,7 @@ function CheckEnvironment {
|
||||||
SUBPROGRAM_EXECUTABLE=/usr/local/bin/$SUBPROGRAM.sh
|
SUBPROGRAM_EXECUTABLE=/usr/local/bin/$SUBPROGRAM.sh
|
||||||
else
|
else
|
||||||
Logger "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" "CRITICAL"
|
Logger "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" "CRITICAL"
|
||||||
|
( >&2 echo "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" )
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -85,56 +86,42 @@ function Batch {
|
||||||
local confFile
|
local confFile
|
||||||
local result
|
local result
|
||||||
|
|
||||||
## Check for CONF_FILE_PATH
|
local i
|
||||||
if [ -d "$CONF_FILE_PATH" ]; then
|
|
||||||
## Get list of .conf files
|
|
||||||
for confFile in $CONF_FILE_PATH/*.conf
|
|
||||||
do
|
|
||||||
if [ -f "$confFile" ]; then
|
|
||||||
if [ "$runList" == "" ]; then
|
|
||||||
runList="$confFile"
|
|
||||||
else
|
|
||||||
runList=$runList" $confFile"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
elif [ -f "$CONF_FILE_PATH" ] && [ "${CONF_FILE_PATH##*.}" == "conf" ]; then
|
|
||||||
runList="$CONF_FILE_PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$runList" == "" ]; then
|
# Using -e because find will accept directories or files
|
||||||
|
if [ ! -e "$CONF_FILE_PATH" ]; then
|
||||||
Logger "Cannot find conf file path [$CONF_FILE_PATH]." "CRITICAL"
|
Logger "Cannot find conf file path [$CONF_FILE_PATH]." "CRITICAL"
|
||||||
Usage
|
Usage
|
||||||
fi
|
else
|
||||||
|
# Ugly hack to read files into an array while preserving special characters
|
||||||
|
runList=()
|
||||||
|
while IFS= read -d $'\0' -r file; do runList+=("$file"); done < <(find "$CONF_FILE_PATH" -iname "*.conf" -print0)
|
||||||
|
|
||||||
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$runList" != "" ] && [ $runs -le $MAX_RUNS ]
|
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "${#runList[@]}" -gt 0 ] && [ $runs -le $MAX_RUNS ]; do
|
||||||
do
|
runAgainList=()
|
||||||
Logger "Sequential run n°$runs of $SUBPROGRAM instances for:" "NOTICE"
|
Logger "Sequential run n°$runs of $SUBPROGRAM instances for:" "NOTICE"
|
||||||
Logger "$runList" "NOTICE"
|
for confFile in "${runList[@]}"; do
|
||||||
for confFile in $runList
|
Logger "$confFile" "NOTICE"
|
||||||
do
|
done
|
||||||
$SUBPROGRAM_EXECUTABLE "$confFile" --silent $opts &
|
for confFile in "${runList[@]}"; do
|
||||||
wait $!
|
$SUBPROGRAM_EXECUTABLE "$confFile" --silent $opts &
|
||||||
result=$?
|
wait $!
|
||||||
if [ $result != 0 ]; then
|
result=$?
|
||||||
if [ $result == 1 ] || [ $result == 128 ]; then # Do not handle exit code 127 because it is already handled here
|
if [ $result != 0 ]; then
|
||||||
Logger "Run instance $(basename $confFile) failed with exit code [$result]." "ERROR"
|
if [ $result == 1 ] || [ $result == 128 ]; then # Do not handle exit code 128 because it is already handled here
|
||||||
if [ "$runAgainList" == "" ]; then
|
Logger "Instance $(basename $confFile) failed with exit code [$result]." "ERROR"
|
||||||
runAgainList="$confFile"
|
runAgainList+=("$confFile")
|
||||||
else
|
elif [ $result == 2 ]; then
|
||||||
runAgainList=$runAgainList" $confFile"
|
Logger "Instance $(basename $confFile) finished with warnings." "WARN"
|
||||||
fi
|
fi
|
||||||
elif [ $result == 2 ]; then
|
else
|
||||||
Logger "Run instance $(basename $confFile) finished with warnings." "WARN"
|
Logger "Instance $(basename $confFile) succeed." "NOTICE"
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
Logger "Run instance $(basename $confFile) succeed." "NOTICE"
|
runList=("${runAgainList[@]}")
|
||||||
fi
|
runs=$(($runs + 1))
|
||||||
done
|
done
|
||||||
runList="$runAgainList"
|
fi
|
||||||
runAgainList=""
|
|
||||||
runs=$(($runs + 1))
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Usage {
|
function Usage {
|
||||||
|
|
Loading…
Reference in New Issue