Blame SOURCES/mysql-wait-ready.sh

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