diff --git a/dev/debug_osync.sh b/dev/debug_osync.sh index 3858639..2ba88ce 100755 --- a/dev/debug_osync.sh +++ b/dev/debug_osync.sh @@ -42,8 +42,8 @@ CONFIG_FILE_REVISION_REQUIRED=1.3.0 # UnlockReplicas yes #__WITH_PARANOIA_DEBUG # CleanUp no #__WITH_PARANOIA_DEBUG -_OFUNCTIONS_VERSION=2.3.0-RC4 -_OFUNCTIONS_BUILD=2020111502 +_OFUNCTIONS_VERSION=2.3.2 +_OFUNCTIONS_BUILD=2021051801 _OFUNCTIONS_BOOTSTRAP=true if ! type "$BASH" > /dev/null; then @@ -1852,6 +1852,42 @@ function RunAfterHook { fi } +function TimeCheck { + # Checks if more than deltatime seconds have passed since last check, which is stored in timefile + __CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG + + local timefile="${1}" + local deltatime="${2}" + + if [ -f "$timefile" ]; then + result=$(cat "$timefile") + tstamp=$(date +%s) + if [ $((tstamp-result)) -gt $deltatime ]; then + echo "$(date +%s)" > "$timefile" + return 0 + else + return 1 + fi + else + echo "$(date +%s)" > "$timefile" + return 0 + fi +} + +function Ping { + # Simple ping check + __CheckArguments 1 $# "$@" + + local host="${1}" + + local retval + + eval "$PING_CMD $host > /dev/null 2>&1" & + ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING + return $? +} + + function CheckConnectivityRemoteHost { __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG @@ -1872,7 +1908,13 @@ function CheckConnectivityRemoteHost { } function CheckConnectivity3rdPartyHosts { - __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG + # Check if at least one host is reachable in order to diag internet + # third_party_hosts_ips=('1.1.1.1' '8.8.8.8' 'kernel.org' 'google.com') + # CheckConnectivity3rdPartyHosts $third_party_hosts_ips + + __CheckArguments 0-1 $# "$@" #__WITH_PARANOIA_DEBUG + + local remote_3rd_party_hosts="${1}" # Optional list of hosts to check local remote3rdPartySuccess local retval @@ -1880,9 +1922,12 @@ function CheckConnectivity3rdPartyHosts { if [ "$_PARANOIA_DEBUG" != true ]; then # Do not loose time in paranoia debug #__WITH_PARANOIA_DEBUG - if [ "$REMOTE_3RD_PARTY_HOSTS" != "" ]; then + if [ "$remote_3rd_party_hosts" == "" ]; then + remote_3rd_party_hosts="$REMOTE_3RD_PARTY_HOSTS" + fi + if [ "$remote_3rd_party_hosts" != "" ]; then remote3rdPartySuccess=false - for i in $REMOTE_3RD_PARTY_HOSTS + for i in $remote_3rd_party_hosts do eval "$PING_CMD $i > /dev/null 2>&1" & ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING @@ -1891,6 +1936,7 @@ function CheckConnectivity3rdPartyHosts { Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE" else remote3rdPartySuccess=true + break fi done @@ -2493,7 +2539,7 @@ function TrapQuit { UnlockReplicas RunAfterHook Logger "$PROGRAM finished." "ALWAYS" - if [ $ALWAYS_SEND_MAILS == true ]; + if [ "$ALWAYS_SEND_MAILS" == true ]; then SendAlert fi diff --git a/install.sh b/install.sh index 325b745..9edb4c0 100755 --- a/install.sh +++ b/install.sh @@ -17,8 +17,8 @@ INSTANCE_ID="installer-$SCRIPT_BUILD" ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11 ## Please adapt this to fit your distro needs -_OFUNCTIONS_VERSION=2.3.0-RC4 -_OFUNCTIONS_BUILD=2020111502 +_OFUNCTIONS_VERSION=2.3.2 +_OFUNCTIONS_BUILD=2021051801 _OFUNCTIONS_BOOTSTRAP=true if ! type "$BASH" > /dev/null; then diff --git a/osync.sh b/osync.sh index aeb0933..eedc3ac 100755 --- a/osync.sh +++ b/osync.sh @@ -13,8 +13,8 @@ IS_STABLE=false CONFIG_FILE_REVISION_REQUIRED=1.3.0 -_OFUNCTIONS_VERSION=2.3.0-RC4 -_OFUNCTIONS_BUILD=2020111502 +_OFUNCTIONS_VERSION=2.3.2 +_OFUNCTIONS_BUILD=2021051801 _OFUNCTIONS_BOOTSTRAP=true if ! type "$BASH" > /dev/null; then @@ -1716,6 +1716,41 @@ function RunAfterHook { fi } +function TimeCheck { + # Checks if more than deltatime seconds have passed since last check, which is stored in timefile + + local timefile="${1}" + local deltatime="${2}" + + if [ -f "$timefile" ]; then + result=$(cat "$timefile") + tstamp=$(date +%s) + if [ $((tstamp-result)) -gt $deltatime ]; then + echo "$(date +%s)" > "$timefile" + return 0 + else + return 1 + fi + else + echo "$(date +%s)" > "$timefile" + return 0 + fi +} + +function Ping { + # Simple ping check + __CheckArguments 1 $# "$@" + + local host="${1}" + + local retval + + eval "$PING_CMD $host > /dev/null 2>&1" & + ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING + return $? +} + + function CheckConnectivityRemoteHost { local retval @@ -1733,15 +1768,24 @@ function CheckConnectivityRemoteHost { } function CheckConnectivity3rdPartyHosts { + # Check if at least one host is reachable in order to diag internet + # third_party_hosts_ips=('1.1.1.1' '8.8.8.8' 'kernel.org' 'google.com') + # CheckConnectivity3rdPartyHosts $third_party_hosts_ips + + + local remote_3rd_party_hosts="${1}" # Optional list of hosts to check local remote3rdPartySuccess local retval local i - if [ "$REMOTE_3RD_PARTY_HOSTS" != "" ]; then + if [ "$remote_3rd_party_hosts" == "" ]; then + remote_3rd_party_hosts="$REMOTE_3RD_PARTY_HOSTS" + fi + if [ "$remote_3rd_party_hosts" != "" ]; then remote3rdPartySuccess=false - for i in $REMOTE_3RD_PARTY_HOSTS + for i in $remote_3rd_party_hosts do eval "$PING_CMD $i > /dev/null 2>&1" & ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING @@ -1750,6 +1794,7 @@ function CheckConnectivity3rdPartyHosts { Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE" else remote3rdPartySuccess=true + break fi done @@ -2344,7 +2389,7 @@ function TrapQuit { UnlockReplicas RunAfterHook Logger "$PROGRAM finished." "ALWAYS" - if [ $ALWAYS_SEND_MAILS == true ]; + if [ "$ALWAYS_SEND_MAILS" == true ]; then SendAlert fi