Blame SOURCES/mysql-wait-ready.sh

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