From d52b6dd5e6c5ebf41d94e005d354c26435a44761 Mon Sep 17 00:00:00 2001 From: deajan Date: Wed, 6 Apr 2016 20:51:29 +0200 Subject: [PATCH] Added an option to run after exec cmds on error --- dev/debug_osync.sh | 11 ++++++++++- dev/n_osync.sh | 11 ++++++++++- osync.sh | 11 ++++++++++- sync.conf | 5 ++++- upgrade-v1.0x-v1.1x.sh | 7 ++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/dev/debug_osync.sh b/dev/debug_osync.sh index 64f8b31..c4064a2 100755 --- a/dev/debug_osync.sh +++ b/dev/debug_osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-pre -PROGRAM_BUILD=2016040603 +PROGRAM_BUILD=2016040604 IS_STABLE=yes ## FUNC_BUILD=2016040602 @@ -1087,6 +1087,9 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with errors." "ERROR" exitcode=1 @@ -1098,11 +1101,17 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with warnings." "WARN" exitcode=240 # Special exit code for daemon mode not stopping on warnings else UnlockReplicas + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished." "NOTICE" exitcode=0 diff --git a/dev/n_osync.sh b/dev/n_osync.sh index 735d9db..45b8803 100755 --- a/dev/n_osync.sh +++ b/dev/n_osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-pre -PROGRAM_BUILD=2016040603 +PROGRAM_BUILD=2016040604 IS_STABLE=yes source "./ofunctions.sh" @@ -38,6 +38,9 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with errors." "ERROR" exitcode=1 @@ -49,11 +52,17 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with warnings." "WARN" exitcode=240 # Special exit code for daemon mode not stopping on warnings else UnlockReplicas + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished." "NOTICE" exitcode=0 diff --git a/osync.sh b/osync.sh index a8495d3..1546151 100755 --- a/osync.sh +++ b/osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-pre -PROGRAM_BUILD=2016040603 +PROGRAM_BUILD=2016040604 IS_STABLE=yes ## FUNC_BUILD=2016040602 @@ -1015,6 +1015,9 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with errors." "ERROR" exitcode=1 @@ -1026,11 +1029,17 @@ function TrapQuit { else Logger "Debug mode, no alert mail will be sent." "NOTICE" fi + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished with warnings." "WARN" exitcode=240 # Special exit code for daemon mode not stopping on warnings else UnlockReplicas + if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then + RunAfterHook + fi CleanUp Logger "$PROGRAM finished." "NOTICE" exitcode=0 diff --git a/sync.conf b/sync.conf index 40b4acc..4de4a90 100644 --- a/sync.conf +++ b/sync.conf @@ -2,7 +2,7 @@ ###### Osync - Rsync based two way sync engine with fault tolerance ###### (C) 2013-2015 by Orsiris "Ozy" de Jong (www.netpower.fr) -###### Config file rev 2016032901 +###### Config file rev 2016040601 ## ---------- GENERAL OPTIONS @@ -161,3 +161,6 @@ MAX_EXEC_TIME_PER_CMD_AFTER=0 ## Stops Osync execution if one of the above commands fail STOP_ON_CMD_ERROR=yes + +## Run local and remote after sync commands even on failure +RUN_AFTER_CMD_ON_ERROR=no diff --git a/upgrade-v1.0x-v1.1x.sh b/upgrade-v1.0x-v1.1x.sh index bb1405c..5b30ac7 100755 --- a/upgrade-v1.0x-v1.1x.sh +++ b/upgrade-v1.0x-v1.1x.sh @@ -6,7 +6,7 @@ AUTHOR="(C) 2015 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" OLD_PROGRAM_VERSION="1.0x" NEW_PROGRAM_VERSION="v1.1x" -PROGRAM_BUILD=2016033102 +PROGRAM_BUILD=2016040601 function Init { OSYNC_DIR=".osync_workdir" @@ -360,6 +360,11 @@ function RewriteConfigFiles { if ! grep "^DELTA_COPIES=" "$config_file" > /dev/null; then sed -i '/^PARTIAL=*/a DELTA_COPIES=yes' "$config_file" fi + + if ! grep "^RUN_AFTER_CMD_ON_ERROR=" "$config_file" > /dev/null; then + sed -i '/^STOP_ON_CMD_ERROR=*/a RUN_AFTER_CMD_ON_ERROR=no' "$config_file" + fi + } _QUICKSYNC=0