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