From f681a34ca5ddae61af7f898709307c05bdd45ed0 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 10 Dec 2004 19:09:25 +0000 Subject: [PATCH] Fix mysql initscript failure when anonymous users are disabled (bz#142328) --- mysql.init | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/mysql.init b/mysql.init index e7ce034..86645a1 100644 --- a/mysql.init +++ b/mysql.init @@ -37,19 +37,18 @@ start(){ chmod 0755 $datadir /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf >/dev/null 2>&1 & ret=$? - # If you've removed anonymous users, this line must be changed to - # use a user that is allowed to ping mysqld. - ping="/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping" - # Spin for a maximum of ten seconds waiting for the server to come up + # Spin for a maximum of N seconds waiting for the server to come up. + # Rather than assuming we know a valid username, accept an "access + # denied" response as meaning the server is functioning. if [ $ret -eq 0 ]; then - for x in 1 2 3 4 5 6 7 8 9 10; do - if [ -n "`$ping 2> /dev/null`" ]; then - break; - else - sleep 1; - fi - done - if !([ -n "`$ping 2> /dev/null`" ]); then + STARTTIMEOUT=10 + while [ $STARTTIMEOUT -gt 0 ]; do + RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2>&1` && break + echo "$RESPONSE" | grep -q "Access denied for user" && break + sleep 1 + let STARTTIMEOUT=${STARTTIMEOUT}-1 + done + if [ $STARTTIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to start MySQL Daemon." action $"Starting $prog: " /bin/false else