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