From dba1c6658225ebe24d598fa5f58a874d36264996 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Sat, 10 Dec 2011 17:27:43 +0100 Subject: mysql 5.5.18, sync with rawhide --- mysqld-nowatch.patch | 51 ++++++++++++++++++++++++++++++++++++++++++++++ mysqld-prepare-db-dir | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ mysqld-wait-ready | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ mysqld.service | 24 ++++++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 mysqld-nowatch.patch create mode 100644 mysqld-prepare-db-dir create mode 100644 mysqld-wait-ready create mode 100644 mysqld.service diff --git a/mysqld-nowatch.patch b/mysqld-nowatch.patch new file mode 100644 index 0000000..9ca2d12 --- /dev/null +++ b/mysqld-nowatch.patch @@ -0,0 +1,51 @@ +Add a --nowatch option to mysqld_safe that causes it to exit after +spawning mysqld. We don't need mysqld_safe to restart mysqld after +a crash, because systemd can do that just fine. + + +diff -Naur mysql-5.5.14.orig/scripts/mysqld_safe.sh mysql-5.5.14/scripts/mysqld_safe.sh +--- mysql-5.5.14.orig/scripts/mysqld_safe.sh 2011-06-21 12:42:40.000000000 -0400 ++++ mysql-5.5.14/scripts/mysqld_safe.sh 2011-07-25 13:52:40.363068060 -0400 +@@ -15,6 +15,7 @@ + KILL_MYSQLD=1; + MYSQLD= + niceness=0 ++nowatch=0 + mysqld_ld_preload= + mysqld_ld_library_path= + +@@ -54,6 +55,7 @@ + --mysqld=FILE Use the specified file as mysqld + --mysqld-version=VERSION Use "mysqld-VERSION" as mysqld + --nice=NICE Set the scheduling priority of mysqld ++ --nowatch Exit after starting mysqld + --plugin-dir=DIR Plugins are under DIR or DIR/VERSION, if + VERSION is given + --skip-kill-mysqld Don't try to kill stray mysqld processes +@@ -140,8 +142,16 @@ + ;; + esac + +- #echo "Running mysqld: [$cmd]" +- eval "$cmd" ++ if test $nowatch -eq 1 ++ then ++ # We'd prefer to exec $cmd here, but SELinux needs to be fixed first ++ #/usr/bin/logger "Running mysqld: $cmd" ++ eval "$cmd &" ++ exit 0 ++ else ++ #echo "Running mysqld: [$cmd]" ++ eval "$cmd" ++ fi + } + + shell_quote_string() { +@@ -198,6 +208,7 @@ + fi + ;; + --nice=*) niceness="$val" ;; ++ --nowatch) nowatch=1 ;; + --open-files-limit=*) open_files="$val" ;; + --open_files_limit=*) open_files="$val" ;; + --skip-kill-mysqld*) KILL_MYSQLD=0 ;; diff --git a/mysqld-prepare-db-dir b/mysqld-prepare-db-dir new file mode 100644 index 0000000..72badd7 --- /dev/null +++ b/mysqld-prepare-db-dir @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script creates the mysql data directory during first service start. +# In subsequent starts, it does nothing much. + +# 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_safe log-error "/var/log/mysqld.log" +errlogfile="$result" + + +# Set up the errlogfile with appropriate permissions +touch "$errlogfile" +chown mysql:mysql "$errlogfile" +chmod 0640 "$errlogfile" +[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" + +# Make the data directory +if [ ! -d "$datadir/mysql" ] ; then + # First, make sure $datadir is there with correct permissions + # (note: if it's not, and we're not root, this'll fail ...) + if [ ! -e "$datadir" -a ! -h "$datadir" ] + then + mkdir -p "$datadir" || exit 1 + fi + chown mysql:mysql "$datadir" + chmod 0755 "$datadir" + [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir" + + # Now create the database + echo "Initializing MySQL database" + /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql + ret=$? + chown -R mysql:mysql "$datadir" + if [ $ret -ne 0 ] ; then + exit $ret + fi +fi + +exit 0 diff --git a/mysqld-wait-ready b/mysqld-wait-ready new file mode 100644 index 0000000..10e86fe --- /dev/null +++ b/mysqld-wait-ready @@ -0,0 +1,56 @@ +#!/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 diff --git a/mysqld.service b/mysqld.service new file mode 100644 index 0000000..b3bc486 --- /dev/null +++ b/mysqld.service @@ -0,0 +1,24 @@ +[Unit] +Description=MySQL database server +After=syslog.target +After=network.target + +[Service] +Type=forking +User=mysql +Group=mysql + +ExecStartPre=/usr/libexec/mysqld-prepare-db-dir +# Note: we set --basedir to prevent probes that might trigger SELinux alarms, +# per bug #547485 +ExecStart=/usr/bin/mysqld_safe --nowatch --basedir=/usr +ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID + +# Give a reasonable amount of time for the server to start up/shut down +TimeoutSec=300 + +# We rely on systemd, not mysqld_safe, to restart mysqld if it dies +Restart=always + +[Install] +WantedBy=multi-user.target -- cgit