do mysql connection check for all scripts, found out hard way vmail-purge-dirs.sh wipes out all email data if it can not connect to mysql

This commit is contained in:
Matthew Saunders Brown 2025-02-27 15:46:37 -08:00
parent fff2b4728f
commit 3083dc6e29

View File

@ -30,29 +30,24 @@ else
fi fi
fi fi
# Only Debian-exim commands do not require MySQL running, (almost) all others do: # check that MYSQL_CONNECTION_INFO_FILE exists and is readable
if [[ "$USER" != "Debian-exim" ]]; then if [ ! -f "$MYSQL_CONNECTION_INFO_FILE" ]; 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." echo "ERROR: MySQL connection info file ($MYSQL_CONNECTION_INFO_FILE) does not exist or is not readable."
exit 1 exit 1
fi fi
# check that MySQL is running # check that MySQL is running
if ! systemctl --quiet is-active mariadb.service if ! systemctl --quiet is-active mariadb.service
then then
echo "MySQL (MariaDB) is not running." echo "MySQL (MariaDB) is not running."
exit 1 exit 1
fi fi
# check vmail MySQL connection/authentication # check vmail MySQL connection/authentication
if ! mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e '\q' if ! mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e '\q'
then then
echo "MySQL connection failed. Check auth info in $MYSQL_CONNECTION_INFO_FILE" echo "MySQL connection failed. Check auth info in $MYSQL_CONNECTION_INFO_FILE"
exit 1 exit 1
fi
fi fi
# functions # functions