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