ganapathi / rpms / mariadb

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