summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-01-13 15:26:44 +0100
committerChristian Grothoff <christian@grothoff.org>2024-01-13 15:26:44 +0100
commit9afe2f07bf4405aa4645bdaeb294d15c1c3f94a6 (patch)
tree3fa1615bf5763a1654a578d5e88f7d2455c3555b
parent7fec3a399aa0dbe1cad881046b3317554273e1ce (diff)
downloadtaler-mdb-9afe2f07bf4405aa4645bdaeb294d15c1c3f94a6.tar.gz
taler-mdb-9afe2f07bf4405aa4645bdaeb294d15c1c3f94a6.tar.bz2
taler-mdb-9afe2f07bf4405aa4645bdaeb294d15c1c3f94a6.zip
have script to show error diagnostics
-rw-r--r--Makefile.am8
-rw-r--r--configure.ac1
-rw-r--r--contrib/Makefile.am9
-rwxr-xr-xcontrib/taler-mdb-network-check.sh187
4 files changed, 199 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index 40e718c..151a99c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,6 @@
-SUBDIRS = src .
+SUBDIRS = contrib src .
EXTRA_DIST = \
- AUTHORS \
- contrib/uncrustify.cfg \
- contrib/uncrustify_precommit
+ AUTHORS
ACLOCAL_AMFLAGS = -I m4
-
-
diff --git a/configure.ac b/configure.ac
index 7732561..f26711d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -274,6 +274,7 @@ LIBS=$LIBS_SAVE
AC_CONFIG_FILES([Makefile
+ contrib/Makefile
src/Makefile])
AC_OUTPUT
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 0000000..ade84a2
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1,9 @@
+SUBDIRS = .
+
+bin_SCRIPTS = \
+ taler-mdb-network-check.sh
+
+EXTRA_DIST = \
+ $(bin_SCRIPTS) \
+ uncrustify.cfg \
+ uncrustify_precommit
diff --git a/contrib/taler-mdb-network-check.sh b/contrib/taler-mdb-network-check.sh
new file mode 100755
index 0000000..1c809e9
--- /dev/null
+++ b/contrib/taler-mdb-network-check.sh
@@ -0,0 +1,187 @@
+#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2023, 2024 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or
+# (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with TALER; see the file COPYING. If not, see
+# <http://www.gnu.org/licenses/>
+#
+# Author: Christian Grothoff
+#
+# Script to test for network connectivity, and if
+# successful launch some "main" application. If
+# the network goes down, stop the "main" application
+# and show an error message.
+#
+
+set -eu
+
+EXIT_STATUS=0
+CHILD_PID=-1
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+ echo " FAILURE:" "$@" >&2
+ EXIT_STATUS=1
+ exit "$EXIT_STATUS"
+}
+
+CONF="$HOME/.config/taler.conf"
+FAIL_PROG="echo"
+
+# Parse command-line options
+while getopts ':c:f:ht:' OPTION; do
+ case "$OPTION" in
+ c)
+ CONF="$OPTARG"
+ ;;
+ f)
+ FAIL_PROG="$OPTARG"
+ ;;
+ h)
+ echo 'Supported options:'
+ # shellcheck disable=SC2016
+ echo ' -c $CONF -- set configuration'
+ # shellcheck disable=SC2016
+ echo ' -f $CMD -- command to run to display failures'
+ # shellcheck disable=SC2016
+ echo ' -t $HOSTNAME -- target hostname (required)'
+ ;;
+ t)
+ BACKEND_HOSTNAME="$OPTARG"
+ ;;
+ ?)
+ exit_fail "Unrecognized command line option"
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [[ "${BACKEND_HOSTNAME:-}" == "" ]]
+then
+ exit_fail "Specifying '-t' is required"
+fi
+
+dig -h > /dev/null || exit_fail "'dig' is required"
+
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+ echo "network-check terminating!" >&2
+
+ for n in $(jobs -p)
+ do
+ kill "$n" 2> /dev/null || true
+ done
+ wait
+ exit "$EXIT_STATUS"
+}
+
+# Function called with the short-hand of a detected
+# Failure. Stop our child (if any) and show it.
+function show_failure()
+{
+ if [ "$CHILD_PID" != "-1" ]
+ then
+ kill -TERM "$CHILD_PID"
+ wait
+ CHILD_PID="-1"
+ fi
+ ${FAIL_PROG} "$1" >&2
+}
+
+# Function to run when our child died.
+function childdeath()
+{
+ wait ${CHILD_PID}
+ CHILD_PID="-1"
+ show_failure child-died
+}
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+trap childdeath SIGCHLD
+
+# shellcheck disable=SC2120
+function check_network()
+{
+ DNS_HOST=$(grep nameserver /etc/resolv.conf | awk '{print $2}')
+ if ! ping -c1 "$DNS_HOST" &> /dev/null
+ then
+ show_failure no-ip
+ return
+ fi
+ if ! dig "$BACKEND_HOSTNAME" &> /dev/null
+ then
+ show_failure backend-dns-resolution-failure
+ return
+ fi
+ if ! ping -c1 "$BACKEND_HOSTNAME" &> /dev/null
+ then
+ show_failure backend-unreachable
+ return
+ fi
+
+ DEF_BACKEND=$(taler-config -c "$CONF" -s "taler-mdb" -o "BACKEND_BASE_URL")
+ if echo "$DEF_BACKEND" | grep "https://" > /dev/null
+ then
+ if ! wget --no-check-certificate "${DEF_BACKEND}config" -O /dev/null &> /dev/null
+ then
+ show_failure backend-no-web-server
+ return
+ fi
+ fi
+
+ if ! wget "${DEF_BACKEND}config" -O /dev/null &> /dev/null
+ then
+ show_failure backend-x509-cert-bad
+ return
+ fi
+
+ HAVE_PRODUCT=0
+ for PS in $(taler-config -c "$CONF" -S | grep "product-" | head -n1)
+ do
+ URL=$(taler-config -c "$CONF" -s "$PS" -o "INSTANCE" 2> /dev/null || echo "$DEF_BACKEND")
+ AUTH=$(taler-config -c "$CONF" -s "$PS" -o "BACKEND_AUTHORIZATION")
+
+ if ! wget --header "Authorization: $AUTH" "${URL}private/orders" -O /dev/null &> /dev/null
+ then
+ echo "Failed to access backend for product '$PS'" >&2
+ else
+ HAVE_PRODUCT=1
+ fi
+ done
+ if [ "$HAVE_PRODUCT" = 0 ]
+ then
+ show_failure backend-auth-failure
+ return
+ fi
+ echo "Network OK, starting child"
+
+ if [ "${CHILD_PID}" = "-1" ]
+ then
+ # shellcheck disable=SC2068
+ $@ &
+ CHILD_PID=$!
+ fi
+}
+
+
+# Check network status
+while true
+do
+ check_network
+ sleep 30
+done