Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > c05d78206daa5de0b42ebaa78271fb20 > files > 10

mariadb-5.5.28-13.mga3.src.rpm

diff -Naur 5.5_orig/support-files/mysql.server.sh 5.5/support-files/mysql.server.sh
--- 5.5_orig/support-files/mysql.server.sh	2011-11-01 16:20:49.000000000 +0100
+++ 5.5/support-files/mysql.server.sh	2011-11-05 11:22:28.185233991 +0100
@@ -10,14 +10,14 @@
 # started and shut down when the systems goes down.
 
 # Comments to support chkconfig on RedHat Linux
-# chkconfig: 2345 64 36
+# chkconfig: 2345 11 90
 # description: A very fast and reliable SQL database engine.
 
 # Comments to support LSB init script conventions
 ### BEGIN INIT INFO
-# Provides: mysql
+# Provides: mysqld
 # Required-Start: $local_fs $network $remote_fs
-# Should-Start: ypbind nscd ldap ntpd xntpd
+# Should-Start: ypbind ldap ntpd
 # Required-Stop: $local_fs $network $remote_fs
 # Default-Start:  2 3 4 5
 # Default-Stop: 0 1 6
@@ -43,6 +43,9 @@
 # If you change base dir, you must also change datadir. These may get
 # overwritten by settings in the MySQL configuration files.
 
+# Source function library.
+. /etc/rc.d/init.d/functions
+
 basedir=
 datadir=
 
@@ -55,7 +58,7 @@
 
 # Lock directory for RedHat / SuSE.
 lockdir='/var/lock/subsys'
-lock_file_path="$lockdir/mysql"
+lock_file_path="$lockdir/mysqld"
 
 # The following variables are only set for letting mysql.server find things.
 
@@ -107,6 +110,9 @@
   }
 fi
 
+# Source mysql configuration.
+[ -f /etc/sysconfig/mysqld ] && . /etc/sysconfig/mysqld
+
 PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
 export PATH
 
@@ -130,18 +136,12 @@
   for arg do
     case "$arg" in
       --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
-                    bindir="$basedir/bin"
+                    bindir="@bindir@"
 		    if test -z "$datadir_set"; then
-		      datadir="$basedir/data"
+		      datadir="@localstatedir@"
 		    fi
-		    sbindir="$basedir/sbin"
-                    if test -f "$basedir/bin/mysqld"
-                    then
-                      libexecdir="$basedir/bin"
-                    else
-                      libexecdir="$basedir/libexec"
-                    fi
-		    libexecdir="$basedir/libexec"
+		    sbindir="@sbindir@"
+		    libexecdir="@libexecdir@"
         ;;
       --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
 		    datadir_set=1
@@ -189,7 +189,7 @@
         fi
 
         # there's nothing that will affect the file.
-        log_failure_msg "The server quit without updating PID file ($pid_file_path)."
+        log_failure_msg "The server quit without updating PID file ($pid_file_path)."; echo
         return 1  # not waiting any more.
       fi
     fi
@@ -200,6 +200,18 @@
 
   done
 
+    # wait for mysql to really be available
+    if test "$verb" = "created"; then
+	i=0
+	echo $echo_n ",$echo_c"
+	while test $i -ne $service_startup_timeout; do
+	    $bindir/mysqladmin ping > /dev/null 2>&1 && i='' && break
+	    echo $echo_n ".$echo_c"
+	    i=`expr $i + 1`
+	    sleep 1
+	done
+    fi
+
   if test -z "$i" ; then
     log_success_msg
     return 0
@@ -286,13 +298,71 @@
     # Safeguard (relative paths, core dumps..)
     cd $basedir
 
-    echo $echo_n "Starting MySQL"
+    # Bail out if there's no valid $datadir (/var/lib/mysql)
+    if ! [ "$datadir" != "/" ]; then
+        echo $echo_n "ERROR: invalid datadir ($datadir)"
+        failure; echo
+        exit 1
+    fi
+
+    # Install a new database if $datadir/mysql is empty.
+    if [ `ls -1A $datadir/mysql|wc -l` == "0" ]; then
+	echo "Initializing the system database: "
+	TMPDIR=/var/tmp $bindir/mysql_install_db
+	RETVAL=$?
+	    if [ "$RETVAL" -gt "0" ]; then
+		echo "ERROR: The database could not be initialized."
+		failure; echo
+		exit 1
+	    fi
+	# Assume this is a clean install when the above checks has passed.
+	$libexecdir/mysqld --version | awk '{ print $3}' > $datadir/mysql_upgrade_info
+	chown -R $user:$user "$datadir"
+	chmod 0711 "$datadir"
+    fi
+
+    # play safe...
+    if ! [ -f $datadir/mysql_upgrade_info ]; then
+	$libexecdir/mysqld --version | awk '{ print $3}' > $datadir/mysql_upgrade_info
+    fi
+
+    # Check if the system database should be updated and alert the user.
+    NEW_VER="`$libexecdir/mysqld --version | cut -d' ' -f4 | cut -d- -f 1`"
+    OLD_VER="`cat $datadir/mysql_upgrade_info | cut -d' ' -f4 | cut -d- -f 1`"
+
+    get_mysql_id() {
+	MAJOR="`echo $1|cut -d. -f1`"; MINOR="`echo $1|cut -d. -f2`"; PATCH="`echo $1|cut -d. -f3`"
+	expr 10000 \* ${MAJOR} + 100 \* ${MINOR} + ${PATCH}
+    }
+
+    if [ "`get_mysql_id $NEW_VER`" -gt "`get_mysql_id $OLD_VER`" ]; then
+        upgrade_message="WARNING: mysql_upgrade should be run (as root). The upgrade from mysql-$OLD_VER to mysql-$NEW_VER may require it."
+        echo $echo_n "$upgrade_message"
+        logger -p daemon.info -t mysql $upgrade_message
+        echo
+    fi
+
+    # Remove stale pidfiles.
+    if [ -z "`/sbin/pidof $libexecdir/mysqld`" ] && [ -e $mysqld_pid_file_path ]; then
+      echo $echo_n "Removing stale pid file (mysqld)."
+      rm -f $mysqld_pid_file_path
+      echo
+    fi
+
+    mysqld_safe_pid=`ps ax | grep $bindir/mysqld_safe | grep -v grep | awk '{ print $1 }'`
+    if ! [ -z $mysqld_safe_pid ]; then
+      echo $echo_n "mysqld_safe is already running: "
+      failure; echo
+      exit 1
+    fi
+
+    echo $echo_n "Starting MySQL: "
     if test -x $bindir/mysqld_safe
     then
       # Give extra arguments to mysqld with the my.cnf file. This script
       # may be overwritten at next upgrade.
       $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
-      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
+      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?; echo
 
       # Make lock for RedHat / SuSE
       if test -w "$lockdir"
@@ -302,7 +372,7 @@
 
       exit $return_value
     else
-      log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
+      log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"; echo
     fi
     ;;
 
@@ -316,12 +386,12 @@
 
       if (kill -0 $mysqld_pid 2>/dev/null)
       then
-        echo $echo_n "Shutting down MySQL"
+        echo $echo_n "Shutting down MySQL: "
         kill $mysqld_pid
         # mysqld should remove the pid file when it exits, so wait for it.
-        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
+        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?; echo
       else
-        log_failure_msg "MySQL server process #$mysqld_pid is not running!"
+        log_failure_msg "MySQL server process #$mysqld_pid is not running!"; echo
         rm "$mysqld_pid_file_path"
       fi
 
@@ -332,7 +402,7 @@
       fi
       exit $return_value
     else
-      log_failure_msg "MySQL server PID file could not be found!"
+      log_failure_msg "MySQL server PID file could not be found!"; echo
     fi
     ;;
 
@@ -342,7 +412,7 @@
     if $0 stop  $other_args; then
       $0 start $other_args
     else
-      log_failure_msg "Failed to stop running server, so refusing to try to start."
+      log_failure_msg "Failed to stop running server, so refusing to try to start."; echo
       exit 1
     fi
     ;;
@@ -350,10 +420,10 @@
   'reload'|'force-reload')
     if test -s "$mysqld_pid_file_path" ; then
       read mysqld_pid <  "$mysqld_pid_file_path"
-      kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
-      touch "$mysqld_pid_file_path"
+      kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL: "
+      touch "$mysqld_pid_file_path"; echo
     else
-      log_failure_msg "MySQL PID file could not be found!"
+      log_failure_msg "MySQL PID file could not be found!"; echo
       exit 1
     fi
     ;;
@@ -362,10 +432,10 @@
     if test -s "$mysqld_pid_file_path" ; then 
       read mysqld_pid < "$mysqld_pid_file_path"
       if kill -0 $mysqld_pid 2>/dev/null ; then 
-        log_success_msg "MySQL running ($mysqld_pid)"
+        log_success_msg "MySQL running ($mysqld_pid)"; echo
         exit 0
       else
-        log_failure_msg "MySQL is not running, but PID file exists"
+        log_failure_msg "MySQL is not running, but PID file exists"; echo
         exit 1
       fi
     else
@@ -373,13 +443,13 @@
       mysqld_pid=`pidof $libexecdir/mysqld`
       if test -z $mysqld_pid ; then 
         if test -f "$lock_file_path" ; then 
-          log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
+          log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"; echo
           exit 2
         fi 
-        log_failure_msg "MySQL is not running"
+        log_failure_msg "MySQL is not running"; echo
         exit 3
       else
-        log_failure_msg "MySQL is running but PID file could not be found"
+        log_failure_msg "MySQL is running but PID file could not be found"; echo
         exit 4
       fi
     fi