Blame SOURCES/mysql-wait-ready.sh

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