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