From f669ccbe163c6c49c0a8d4ea6c97a202187277b0 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Fri, 24 Jan 2025 14:05:07 -0800 Subject: [PATCH] add checks that mysql is running and auth works --- bin/vmail.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/vmail.sh b/bin/vmail.sh index 9dd8cc1..1ce089b 100755 --- a/bin/vmail.sh +++ b/bin/vmail.sh @@ -27,15 +27,34 @@ elif [[ $(basename $0) == "vmail-purge-spool.sh" ]]; then else if [[ "$USER" != "vmail" ]]; then exec sudo -u vmail $0 "$@" - else - # check that MYSQL_CONNECTION_INFO_FILE exists and is readable - if [ ! -f "$MYSQL_CONNECTION_INFO_FILE" ]; then - echo "ERROR: MySQL connection info file ($MYSQL_CONNECTION_INFO_FILE) does not exist or is not readable." - exit 1 - fi fi fi +# Only Debian-exim commands do not require MySQL running, (almost) all others do: +if [[ "$USER" != "Debian-exim" ]]; then + + # check that MYSQL_CONNECTION_INFO_FILE exists and is readable + if [ ! -f "$MYSQL_CONNECTION_INFO_FILE" ]; then + echo "ERROR: MySQL connection info file ($MYSQL_CONNECTION_INFO_FILE) does not exist or is not readable." + exit 1 + fi + + # check that MySQL is running + if ! systemctl --quiet is-active mariadb.service + then + echo "MySQL (MariaDB) is not running." + exit 1 + fi + + # check vmail MySQL connection/authentication + if ! mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e '\q' + then + echo "MySQL connection failed. Check auth info in $MYSQL_CONNECTION_INFO_FILE" + exit 1 + fi + +fi + # functions # crude but good enough domain name format validation