Coding style compliance continues

pull/36/head
deajan 9 years ago
parent a2c9d4860b
commit b9bfbb3974

@ -64,3 +64,11 @@ The eval command should always contain 2>1&.
There's a special case where this is needed: There's a special case where this is needed:
eval "some;commands" 2>> "$LOG_FILE" in order to get error messages into the log. eval "some;commands" 2>> "$LOG_FILE" in order to get error messages into the log.
7. Version numbering
Using bind style versionning:
YYYYMMDDVV (Year, Month, Day, Revision)
Ex:
2015012402 = 2nd revision of 24 Jan 2015

@ -3,7 +3,7 @@
PROGRAM="Osync-batch" # Batch program to run osync instances sequentially and rerun failed ones PROGRAM="Osync-batch" # Batch program to run osync instances sequentially and rerun failed ones
AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong" AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_BUILD=2015082501 PROGRAM_BUILD=2015090801
## Runs an osync instance for every conf file found ## Runs an osync 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
@ -19,44 +19,74 @@ MAX_RERUNS=3
## Log file path ## Log file path
if [ -w /var/log ]; then if [ -w /var/log ]; then
LOG_FILE=/var/log/osync-batch.log LOG_FILE=/var/log/osync-batch.log
else else
LOG_FILE=./osync-batch.log LOG_FILE=./osync-batch.log
fi fi
# No need to edit under this line ############################################################## # No need to edit under this line ##############################################################
function Log { function _logger {
prefix="TIME: $SECONDS - " local value="${1}" # What to log
echo -e "$prefix$1" >> "$LOG_FILE" echo -e "$value" >> "$LOG_FILE"
if [ $silent -eq 0 ] if [ $silent -eq 0 ]; then
then echo -e "$value"
echo -e "$prefix$1" fi
fi }
function Logger {
local value="${1}" # What to log
local level="${2}" # Log level: DEBUG, NOTICE, WARN, ERROR, CRITIAL
# Special case in daemon mode we should timestamp instead of counting seconds
if [ $sync_on_changes -eq 1 ]; then
prefix="$(date) - "
else
prefix="TIME: $SECONDS - "
fi
if [ "$level" == "CRITICAL" ]; then
_logger "$prefix\e[41m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "ERROR" ]; then
_logger "$prefix\e[91m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "WARN" ]; then
_logger "$prefix\e[93m$value\e[0m"
elif [ "$level" == "NOTICE" ]; then
_logger "$prefix$value"
elif [ "$level" == "DEBUG" ]; then
if [ "$DEBUG" == "yes" ]; then
_logger "$prefix$value"
fi
else
_logger "\e[41mLogger function called without proper loglevel.\e[0m"
_logger "$prefix$value"
fi
} }
function CheckEnvironment { function CheckEnvironment {
## Osync executable full path can be set here if it cannot be found on the system ## Osync executable full path can be set here if it cannot be found on the system
if ! type -p osync.sh > /dev/null 2>&1 if ! type -p osync.sh > /dev/null 2>&1
then then
if [ -f /usr/local/bin/osync.sh ] if [ -f /usr/local/bin/osync.sh ]
then then
OSYNC_EXECUTABLE=/usr/local/bin/osync.sh OSYNC_EXECUTABLE=/usr/local/bin/osync.sh
elif [ -f ./osync.sh ] elif [ -f ./osync.sh ]
then then
OSYNC_EXECUTABLE=./osync.sh OSYNC_EXECUTABLE=./osync.sh
else else
Log "Could not find osync.sh" Logger "Could not find osync.sh" "CRITICAL"
exit 1 exit 1
fi fi
else else
OSYNC_EXECUTABLE=$(type -p osync.sh) OSYNC_EXECUTABLE=$(type -p osync.sh)
fi fi
## Check for CONF_FILE_PATH ## Check for CONF_FILE_PATH
if [ ! -d "$CONF_FILE_PATH" ]; then if [ ! -d "$CONF_FILE_PATH" ]; then
Log "Cannot find conf file path $CONF_FILE_PATH" Logger "Cannot find conf file path $CONF_FILE_PATH" "CRITICAL"
Usage Usage
fi fi
} }
@ -75,19 +105,19 @@ function Batch {
RERUNS=0 RERUNS=0
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ] while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
do do
Log "Osync instances will be run for: $RUN" Logger "Osync instances will be run for: $RUN" "NOTICE"
for i in $RUN for i in $RUN
do do
$OSYNC_EXECUTABLE "$i" $opts $OSYNC_EXECUTABLE "$i" $opts
if [ $? != 0 ]; then if [ $? != 0 ]; then
Log "Run instance $(basename $i) failed" Logger "Run instance $(basename $i) failed" "ERROR"
if [ "RUN_AGAIN" == "" ]; then if [ "RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i" RUN_AGAIN="$i"
else else
RUN_AGAIN=$RUN_AGAIN" $i" RUN_AGAIN=$RUN_AGAIN" $i"
fi fi
else else
Log "Run instance $(basename $i) succeed." Logger "Run instance $(basename $i) succeed." "NOTICE"
fi fi
done done
RUN="$RUN_AGAIN" RUN="$RUN_AGAIN"
@ -97,22 +127,22 @@ function Batch {
} }
function Usage { function Usage {
echo "$PROGRAM $PROGRAM_BUILD" echo "$PROGRAM $PROGRAM_BUILD"
echo $AUTHOR echo $AUTHOR
echo $CONTACT echo $CONTACT
echo "" echo ""
echo "Batch script to sequentially run osync instances and rerun failed ones." echo "Batch script to sequentially run osync instances and rerun failed ones."
echo "Usage: osync-batch.sh [OPTIONS]" echo "Usage: osync-batch.sh [OPTIONS]"
echo "" echo ""
echo "[OPTIONS]" echo "[OPTIONS]"
echo "--path=/path/to/conf Path to osync conf files, defaults to /etc/osync" echo "--path=/path/to/conf Path to osync conf files, defaults to /etc/osync"
echo "--max-reruns=X Number of runs max for failed instances, (defaults to 3)" echo "--max-reruns=X Number of runs max for failed instances, (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 without honoring conf file defined timeouts" echo "--no-maxtime Run osync without honoring conf file defined timeouts"
echo "--dry Will run osync without actually doing anything; just testing" echo "--dry Will run osync without actually doing anything; just testing"
echo "--silent Will run osync without any output to stdout, used for cron jobs" echo "--silent Will run osync without any output to stdout, used for cron jobs"
echo "--verbose Increases output" echo "--verbose Increases output"
exit 128 exit 128
} }
silent=0 silent=0
@ -121,18 +151,18 @@ verbose=0
opts="" opts=""
for i in "$@" for i in "$@"
do do
case $i in case $i in
--silent) --silent)
silent=1 silent=1
opts=$opts" --silent" opts=$opts" --silent"
;; ;;
--dry) --dry)
dry=1 dry=1
opts=$opts" --dry" opts=$opts" --dry"
;; ;;
--verbose) --verbose)
verbose=1 verbose=1
opts=$opts" --verbose" opts=$opts" --verbose"
;; ;;
--no-maxtime) --no-maxtime)
opts=$opts" --no-maxtime" opts=$opts" --no-maxtime"
@ -150,12 +180,12 @@ do
Usage Usage
;; ;;
*) *)
Log "Unknown param '$i'" Logger "Unknown param '$i'" "CRITICAL"
Usage Usage
;; ;;
esac esac
done done
CheckEnvironment CheckEnvironment
Log "$(date) Osync batch run" Logger "$(date) Osync batch run" "NOTICE"
Batch Batch

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
##### Osync ssh command filter build 2015070203 ##### Osync ssh command filter build 2015090801
##### This script should be located in /usr/local/bin in the remote system to sync / backup ##### This script should be located in /usr/local/bin in the remote system to sync / backup
##### It will filter the commands that can be run remotely via ssh. ##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file ##### Please chmod 755 and chown root:root this file
@ -65,21 +65,21 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then if [ "$CMD1" != "" ]; then
Go Go

Loading…
Cancel
Save