Coding style compliance continues

This commit is contained in:
deajan 2015-09-08 16:16:22 +02:00
parent a2c9d4860b
commit b9bfbb3974
3 changed files with 108 additions and 70 deletions

View File

@ -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

View File

@ -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
@ -26,13 +26,43 @@ 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
}
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 fi
} }
@ -47,7 +77,7 @@ function CheckEnvironment {
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
@ -56,7 +86,7 @@ function CheckEnvironment {
## 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"
@ -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

View File

@ -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