File: //usr/libexec/mysql-wait-ready
#!/bin/sh
# This script waits for mysqld to be ready to accept connections
# (which can be many seconds or even minutes after launch, if there's
# a lot of crash-recovery work to do).
# Running this as ExecStartPost is useful so that services declared as
# "After mysqld" won't be started until the database is really ready.
# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
daemon_pid="$1"
# Wait for the server to come up or for the mysqld process to disappear
ret=0
while /bin/true; do
MYSQLDRUNNING=0
if [ -d "/proc/${daemon_pid}" ] ; then
MYSQLDRUNNING=1
fi
RESPONSE=$(/usr/bin/mysqladmin --defaults-extra-file=/usr/local/directadmin/conf/my.cnf ping 2>&1)
mret=$?
if [ $mret -eq 0 ] && [ $MYSQLDRUNNING -eq 1 ]; then
break
fi
# exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
# anything else suggests a configuration error
if [ $mret -ne 1 ] && [ $mret -ne 11 ]; then
ret=1
break
fi
# "Access denied" also means the server is alive
echo "$RESPONSE" | grep -q "Access denied for user" && break
# Check process still exists
if ! /bin/kill -0 "$daemon_pid" 2>/dev/null; then
ret=1
break
fi
sleep 1
done
exit $ret