Blame SOURCES/mysqld-wait-stop

6f9931
#!/bin/sh
6f9931
6f9931
# This script waits for mysqld to be properly stopped
6f9931
# (which can be many seconds in some large load).
6f9931
# Running this as ExecStopPost is useful so that starting which is done
6f9931
# as part of restart doesn't see the former process still running.
6f9931
6f9931
# extract value of a MySQL option from config files
6f9931
# Usage: get_mysql_option SECTION VARNAME DEFAULT
6f9931
# result is returned in $result
6f9931
# We use my_print_defaults which prints all options from multiple files,
6f9931
# with the more specific ones later; hence take the last match.
6f9931
get_mysql_option(){
6f9931
        result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
6f9931
        if [ -z "$result" ]; then
6f9931
            # not found, use default
6f9931
            result="$3"
6f9931
        fi
6f9931
}
6f9931
6f9931
# Defaults here had better match what mysqld_safe will default to
6f9931
get_mysql_option mysqld_safe pid-file "`hostname`.pid"
6f9931
pidfile="$result"
6f9931
6f9931
# Wait for the server to properly end the main server
6f9931
ret=0
6f9931
TIMEOUT=60
6f9931
SECONDS=0
6f9931
6f9931
if ! [ -f "$pidfile" ]; then
6f9931
	exit 1
6f9931
fi
6f9931
6f9931
MYSQLPID=`cat "$pidfile" 2>/dev/null`
6f9931
if [ -z "$MYSQLPID" ] ; then
6f9931
	exit 2
6f9931
fi
6f9931
6f9931
while /bin/true; do
6f9931
	# Check process still exists
6f9931
	if ! [ -d "/proc/${MYSQLPID}" ] ; then
6f9931
	    break
6f9931
	fi
6f9931
	if [ $SECONDS -gt $TIMEOUT ] ; then
6f9931
	    ret=3
6f9931
	    break
6f9931
	fi
6f9931
	sleep 1
6f9931
done
6f9931
6f9931
exit $ret