← Back to team overview

maria-discuss team mailing list archive

Re: mysqld-wait-ready -> Re: start mariadb randomly fails or answers with wrong response to systemd

 

Am 20.01.2014 15:54, schrieb Sergei Golubchik:
> Hi, Reindl!
> 
> On Jan 16, Reindl Harald wrote:
>>
>> the main question is why is MySQL/MariaDB implemented in a way
>> that mysqld responds with status code *before* it is ready to
>> accept connections at all
> 
> What do you mean by that?
> 
> As far as I can see, MariaDB reports "ready for connections" directly
> before starting to listen for them, there are no time-consuming
> operations in-between. I believe, that for all practical purposes when
> you see "ready for connections", the server is, indeed, ready for
> connections.

"there are no time-consuming operations in-between" is not enough
in case of systemd and as-soon-as-possible parallel startup

in fact systemd calls "ExecStart" and get the zero-return-value from
"/usr/libexec/mysqld" *before* the service really accepts connections
and by nature systemd fires up any unit with After=mysqld.service at
the same time and that leaves a timewindow where these processes are
not able to connect and authenticate to mysqld

that's why "/usr/libexec/mysqld-wait-ready" was needed

introducing systemd with Fedora 15 came without "/usr/libexec/mysqld-wait-ready"
and i had at every reboot random services with error messages or completly
failing to start -> here the history: https://bugzilla.redhat.com/show_bug.cgi?id=714426

that happens without "mysqld-wait-ready"
https://bugzilla.redhat.com/show_bug.cgi?id=714426#c7
________________________________

[Service]
Type=simple
PIDFile=/var/run/mysqld/mysqld.pid
ExecStart=/usr/libexec/mysqld --defaults-file=/etc/my.cnf --pid-file=/var/run/mysqld/mysqld.pid
--socket=/var/lib/mysql/mysql.sock --open-files-limit=750000 --basedir=/usr --user=mysql
ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
________________________________

[root@rh:~]$ cat /usr/libexec/mysqld-wait-ready
#!/bin/sh

# 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.

# Service file passes us the daemon's PID
daemon_pid="$1"

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
 result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
 if [ -z "$result" ]; then
  # not found, use default
  result="$3"
 fi
}

# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"

# Wait for the server to come up or for the mysqld process to disappear
ret=0
while /bin/true; do
 RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
 mret=$?
 if [ $mret -eq 0 ]; then
  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
  ret=1
  break
 fi
 # "Access denied" also means the server is alive
 echo "$RESPONSE" | grep -q "Access denied for user" && break

 # Check process still exists
 if ! /bin/kill -0 $daemon_pid 2>/dev/null; then
  ret=1
  break
 fi
 sleep 1
done

exit $ret

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References