Improved error logging

This commit is contained in:
deajan 2015-07-17 09:47:55 +02:00
parent 6d47ede4e3
commit a3246d785c
2 changed files with 20 additions and 9 deletions

View File

@ -7,6 +7,7 @@ KNOWN ISSUES
RECENT CHANGES RECENT CHANGES
-------------- --------------
- Improved various logging on error
- Work in progress: Unit tests (intial tests written by onovy, Thanks again!) - Work in progress: Unit tests (intial tests written by onovy, Thanks again!)
- Small Improvements on install and ssh_filter scripts - Small Improvements on install and ssh_filter scripts
- Improved ssh uri recognition (thanks to onovy) - Improved ssh uri recognition (thanks to onovy)

View File

@ -4,7 +4,7 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.00pre PROGRAM_VERSION=1.00pre
PROGRAM_BUILD=2015062701 PROGRAM_BUILD=2015071701
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
if ! type -p "$BASH" > /dev/null if ! type -p "$BASH" > /dev/null
@ -705,16 +705,20 @@ function CreateOsyncDirs
then then
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
eval "$SSH_CMD \"if ! [ -d \\\"$SLAVE_STATE_DIR\\\" ]; then $COMMAND_SUDO mkdir -p \\\"$SLAVE_STATE_DIR\\\"; fi\"" & eval "$SSH_CMD \"if ! [ -d \\\"$SLAVE_STATE_DIR\\\" ]; then $COMMAND_SUDO mkdir -p \\\"$SLAVE_STATE_DIR\\\"; fi 2>&1\"" &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 0 1800 WaitForTaskCompletion $child_pid 0 1800
else else
if ! [ -d "$SLAVE_STATE_DIR" ]; then mkdir -p "$SLAVE_STATE_DIR"; fi if ! [ -d "$SLAVE_STATE_DIR" ]
then
mkdir -p "$SLAVE_STATE_DIR" > $RUN_DIR/osync_createosyncdirs_$SCRIPT_PID 2>&1
fi
fi fi
if [ $? != 0 ] if [ $? != 0 ]
then then
LogError "Cannot create slave replica state dir [$SLAVE_STATE_DIR]." LogError "Cannot create slave replica state dir [$SLAVE_STATE_DIR]."
LogErorr "Command output:\n$(cat $RUN_DIR/osync_createosyncdirs_$SCRIPT_PID)"
exit 1 exit 1
fi fi
} }
@ -737,10 +741,11 @@ function CheckMasterSlaveDirs
then then
if [ "$CREATE_DIRS" == "yes" ] if [ "$CREATE_DIRS" == "yes" ]
then then
mkdir -p "$MASTER_SYNC_DIR" mkdir -p "$MASTER_SYNC_DIR" > $RUN_DIR/osync_checkmasterslavedirs_$SCRIPT_PID 2>&1
if [ $? != 0 ] if [ $? != 0 ]
then then
LogError "Cannot create master directory [$MASTER_SYNC_DIR]." LogError "Cannot create master directory [$MASTER_SYNC_DIR]."
LogError "Command output:\n$(cat $RUN_DIR/osync_checkmasterslavedirs_$SCRIPT_PID)"
exit 1 exit 1
fi fi
else else
@ -755,12 +760,13 @@ function CheckMasterSlaveDirs
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
if [ "$CREATE_DIRS" == "yes" ] if [ "$CREATE_DIRS" == "yes" ]
then then
eval "$SSH_CMD \"if ! [ -d \\\"$SLAVE_SYNC_DIR\\\" ]; then $COMMAND_SUDO mkdir -p \\\"$SLAVE_SYNC_DIR\\\"; fi"\" & eval "$SSH_CMD \"if ! [ -d \\\"$SLAVE_SYNC_DIR\\\" ]; then $COMMAND_SUDO mkdir -p \\\"$SLAVE_SYNC_DIR\\\"; fi 2>&1"\" > $RUN_DIR/osync_checkmasterslavedirs_$SCRIPT_PID &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 0 1800 WaitForTaskCompletion $child_pid 0 1800
if [ $? != 0 ] if [ $? != 0 ]
then then
LogError "Cannot create slave directory [$SLAVE_SYNC_DIR]." LogError "Cannot create slave directory [$SLAVE_SYNC_DIR]."
LogError "Command output:\n$(cat $RUN_DIR/osync_checkmasterslavedirs_$SCRIPT_PID)"
exit 1 exit 1
fi fi
else else
@ -997,16 +1003,20 @@ function UnlockDirectories
then then
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
eval "$SSH_CMD \"if [ -f \\\"$SLAVE_LOCK\\\" ]; then $COMMAND_SUDO rm \\\"$SLAVE_LOCK\\\"; fi\"" & eval "$SSH_CMD \"if [ -f \\\"$SLAVE_LOCK\\\" ]; then $COMMAND_SUDO rm \\\"$SLAVE_LOCK\\\"; fi 2>&1\"" > $RUN_DIR/osync_UnlockDirectories_$SCRIPT_PID &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 0 1800 WaitForTaskCompletion $child_pid 0 1800
else else
if [ -f "$SLAVE_LOCK" ];then rm "$SLAVE_LOCK"; fi if [ -f "$SLAVE_LOCK" ]
then
rm "$SLAVE_LOCK" > $RUN_DIR/osync_UnlockDirectories_$SCRIPT_PID 2>&1
fi
fi fi
if [ $? != 0 ] if [ $? != 0 ]
then then
LogError "Could not unlock slave replica." LogError "Could not unlock slave replica."
LogError "Command Output:\n$(cat $RUN_DIR/osync_UnlockDirectories_$SCRIPT_PID)"
else else
Log "Removed slave replica lock." Log "Removed slave replica lock."
fi fi
@ -1645,7 +1655,7 @@ function _SoftDelete
fi fi
if [ $dryrun -ne 1 ] if [ $dryrun -ne 1 ]
then then
$FIND_CMD "$2/" -type f -ctime +$1 -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$2/" -type d -empty -ctime +$1 -print0 | xargs -0 -I {} rm -rf "{}" > $RUN_DIR/osync_soft_delete_master_$SCRIPT_PID & $FIND_CMD "$2/" -type f -ctime +$1 -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$2/" -type d -empty -ctime +$1 -print0 | xargs -0 -I {} rm -rf "{}" > $RUN_DIR/osync_soft_delete_master_$SCRIPT_PID 2>&1 &
else else
Dummy & Dummy &
fi fi
@ -1682,7 +1692,7 @@ function _SoftDelete
fi fi
if [ $dryrun -ne 1 ] if [ $dryrun -ne 1 ]
then then
eval "$SSH_CMD \"if [ -w \\\"$3\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$3/\\\" -type f -ctime +$1 -print0 | xargs -0 -I {} rm -f \\\"{}\\\" && $REMOTE_FIND_CMD \\\"$3/\\\" -type d -empty -ctime $1 -print0 | xargs -0 -I {} rm -rf \\\"{}\\\"; fi\"" > $RUN_DIR/osync_soft_delete_slave_$SCRIPT_PID & eval "$SSH_CMD \"if [ -w \\\"$3\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$3/\\\" -type f -ctime +$1 -print0 | xargs -0 -I {} rm -f \\\"{}\\\" && $REMOTE_FIND_CMD \\\"$3/\\\" -type d -empty -ctime $1 -print0 | xargs -0 -I {} rm -rf \\\"{}\\\"; fi 2>&1\"" > $RUN_DIR/osync_soft_delete_slave_$SCRIPT_PID &
else else
Dummy & Dummy &
fi fi