add checks that mysql is running and auth works

This commit is contained in:
Matthew Saunders Brown 2025-01-24 14:05:07 -08:00
parent 7874a8fadc
commit f669ccbe16

View File

@ -27,13 +27,32 @@ elif [[ $(basename $0) == "vmail-purge-spool.sh" ]]; then
else
if [[ "$USER" != "vmail" ]]; then
exec sudo -u vmail $0 "$@"
else
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