Blame SOURCES/mysql-wait-ready.sh

4b4994
#!/bin/sh
4b4994
4b4994
source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common"
4b4994
4b4994
# This script waits for mysqld to be ready to accept connections
4b4994
# (which can be many seconds or even minutes after launch, if there's
4b4994
# a lot of crash-recovery work to do).
4b4994
# Running this as ExecStartPost is useful so that services declared as
4b4994
# "After mysqld" won't be started until the database is really ready.
4b4994
4b4994
if [ $# -ne 1 ] ; then
4b4994
	echo "You need to pass daemon pid as an argument for this script."
4b4994
	exit 20
4b4994
fi
4b4994
4b4994
# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
4b4994
daemon_pid="$1"
4b4994
4b4994
# Wait for the server to come up or for the mysqld process to disappear
4b4994
ret=0
4b4994
while /bin/true; do
4b4994
	# Check process still exists
4b4994
	if ! [ -d "/proc/${daemon_pid}" ] ; then
4b4994
	    ret=1
4b4994
	    break
4b4994
	fi
4b4994
	RESPONSE=`@bindir@/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
4b4994
	mret=$?
4b4994
	if [ $mret -eq 0 ] ; then
4b4994
	    break
4b4994
	fi
4b4994
	# exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
4b4994
	# anything else suggests a configuration error
4b4994
	if [ $mret -ne 1 -a $mret -ne 11 ]; then
4b4994
            echo "Cannot check for @NICE_PROJECT_NAME@ Daemon startup because of mysqladmin failure." >&2
4b4994
	    ret=$mret
4b4994
	    break
4b4994
	fi
4b4994
	# "Access denied" also means the server is alive
4b4994
	echo "$RESPONSE" | grep -q "Access denied for user" && break
4b4994
4b4994
	sleep 1
4b4994
done
4b4994
4b4994
exit $ret