Simplified batch tool

This commit is contained in:
deajan 2016-11-30 13:28:37 +01:00
parent 92852357e3
commit 8f0efbcb46
1 changed files with 14 additions and 24 deletions

View File

@ -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=2016082901 PROGRAM_BUILD=2016112402
## 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
@ -13,9 +13,6 @@ if ! type "$BASH" > /dev/null; then
exit 127 exit 127
fi fi
## Configuration file path. The path where all the osync / obackup conf files are, usually /etc/osync or /etc/obackup
CONF_FILE_PATH=/etc/$SUBPROGRAM
## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours. ## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours.
MAX_EXECUTION_TIME=36000 MAX_EXECUTION_TIME=36000
@ -74,6 +71,10 @@ function CheckEnvironment {
else else
SUBPROGRAM_EXECUTABLE=$(type -p $SUBPROGRAM.sh) SUBPROGRAM_EXECUTABLE=$(type -p $SUBPROGRAM.sh)
fi fi
if [ "$CONF_FILE_PATH" == "" ]; then
Usage
fi
} }
function Batch { function Batch {
@ -111,7 +112,7 @@ function Batch {
Logger "$SUBPROGRAM instances will be run for: $runList" "NOTICE" Logger "$SUBPROGRAM instances will be run for: $runList" "NOTICE"
for confFile in $runList for confFile in $runList
do do
$SUBPROGRAM_EXECUTABLE "$confFile" $opts & $SUBPROGRAM_EXECUTABLE "$confFile" --silent $opts &
wait $! wait $!
result=$? result=$?
if [ $result != 0 ]; then if [ $result != 0 ]; then
@ -141,16 +142,18 @@ function Usage {
echo $CONTACT echo $CONTACT
echo "" echo ""
echo "Batch script to sequentially run osync or obackup instances and rerun failed ones." echo "Batch script to sequentially run osync or obackup instances and rerun failed ones."
echo "Usage: $SUBPROGRAM-batch.sh [OPTIONS]" echo "Usage: $PROGRAM.sh [OPTIONS] [$SUBPROGRAM OPTIONS]"
echo "" echo ""
echo "[OPTIONS]" echo "[OPTIONS]"
echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup" echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
echo "--max-runs=X Number of max runs per instance, (defaults to 3)" echo "--max-runs=X Number of max runs per instance, (defaults to 3)"
echo "--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check" echo "--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check"
echo "--no-maxtime Run osync / obackup without honoring conf file defined timeouts" echo "[$SUBPROGRAM OPTIONS]"
echo "--dry Will run osync / obackup without actually doing anything; just testing" echo "Specify whatever options $PROGRAM accepts. Example"
echo "--silent Will run osync / obackup without any output to stdout, used for cron jobs" echo "$PROGRAM.sh --path=/etc/$SUBPROGRAM --no-maxtime"
echo "--verbose Increases output" echo ""
echo "No output will be written to stdout/stderr."
echo "Verify log file in [$LOG_FILE]."
exit 128 exit 128
} }
@ -158,18 +161,6 @@ opts=""
for i in "$@" for i in "$@"
do do
case $i in case $i in
--silent)
opts=$opts" --silent"
;;
--dry)
opts=$opts" --dry"
;;
--verbose)
opts=$opts" --verbose"
;;
--no-maxtime)
opts=$opts" --no-maxtime"
;;
--path=*) --path=*)
CONF_FILE_PATH=${i##*=} CONF_FILE_PATH=${i##*=}
;; ;;
@ -183,8 +174,7 @@ do
Usage Usage
;; ;;
*) *)
Logger "Unknown param '$i'" "CRITICAL" opts="$i "
Usage
;; ;;
esac esac
done done