--- support-files/mysql.server.sh 2008-01-11 15:43:29.000000000 +0100 +++ support-files/mysql.server.sh.oden 2008-04-17 12:25:51.000000000 +0200 @@ -9,15 +9,15 @@ # When this is done the mysql server will be started when the machine is # started and shut down when the systems goes down. -# Comments to support chkconfig on RedHat Linux -# chkconfig: 2345 64 36 +# Comments to support chkconfig on Mandriva Linux +# 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 # Required-Start: $local_fs $network $remote_fs -# Should-Start: ypbind nscd ldap ntpd xntpd +# Should-Start: ypbind nscd ldap ntpd # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 @@ -40,6 +40,9 @@ # If you want to affect other MySQL variables, you should make your changes # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. +# Source function library. +. /etc/rc.d/init.d/functions + # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. @@ -58,7 +61,7 @@ # Set some defaults pid_file= server_pid_file= -use_mysqld_safe=1 +use_mysqld_safe=0 user=@MYSQLD_USER@ if test -z "$basedir" then @@ -101,6 +104,9 @@ } fi +# Source mysql configuration. +[ -f /etc/sysconfig/mysqld ] && . /etc/sysconfig/mysqld + PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin export PATH @@ -121,12 +127,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" - libexecdir="$basedir/libexec" + sbindir="@sbindir@" + libexecdir="@libexecdir@" ;; --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` datadir_set=1 @@ -268,6 +274,41 @@ # Safeguard (relative paths, core dumps..) cd $basedir + # Install a new database if $datadir/mysql is empty. + if [ `ls -1A $datadir/mysql|wc -l` == "0" ]; then + + if [ `/bin/hostname` == "localhost" ]; then + echo "ERROR: hostname cannot be localhost, mysql_install_db is quite unstable" + echo "https://qa.mandriva.com/show_bug.cgi?id=38398" + exit 1 + fi + + echo "Initializing MySQL database: " + TMPDIR=/var/tmp $bindir/mysql_install_db + chown -R $user:$user "$datadir" + chmod 0711 "$datadir" + fi + + # Remove stale pidfiles. + if [ -z "`/sbin/pidof mysqlmanager`" ] && [ -e $pid_file ]; then + echo $echo_n "Removing stale pid file (mysqlmanager)." + rm -f $pid_file + echo + fi + + if [ -z "`/sbin/pidof mysqld`" ] && [ -e $server_pid_file ]; then + echo $echo_n "Removing stale pid file (mysqld)." + rm -f $server_pid_file + echo + fi + + # Don't start several instances. + if test -f $pid_file -a -f $server_pid_file; then + echo $echo_n "MySQL is allready running: " + success; echo + exit 1 + fi + manager=$bindir/mysqlmanager if test -x $libexecdir/mysqlmanager then @@ -277,23 +318,23 @@ manager=$sbindir/mysqlmanager fi - echo $echo_n "Starting MySQL" + echo $echo_n "Starting MySQL: " if test -x $manager -a "$use_mysqld_safe" = "0" then if test -n "$other_args" then - log_failure_msg "MySQL manager does not support options '$other_args'" + log_failure_msg "MySQL manager does not support options '$other_args'"; echo exit 1 fi # Give extra arguments to mysqld with the my.cnf file. This script may # be overwritten at next upgrade. - $manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 & - wait_for_pid created $!; return_value=$? + $manager --user=$user --run-as-service --pid-file=$pid_file >/dev/null 2>&1 & + wait_for_pid created $!; return_value=$?; echo - # Make lock for RedHat / SuSE + # Make lock for Mandriva Linux if test -w /var/lock/subsys then - touch /var/lock/subsys/mysqlmanager + touch /var/lock/subsys/mysqlmanager /var/lock/subsys/mysqld fi exit $return_value elif test -x $bindir/mysqld_safe @@ -302,16 +343,16 @@ # may be overwritten at next upgrade. pid_file=$server_pid_file $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 & - wait_for_pid created $!; return_value=$? + wait_for_pid created $!; return_value=$?; echo - # Make lock for RedHat / SuSE + # Make lock for Mandriva Linux if test -w /var/lock/subsys then - touch /var/lock/subsys/mysql + touch /var/lock/subsys/mysqld fi exit $return_value else - log_failure_msg "Couldn't find MySQL manager or server" + log_failure_msg "Couldn't find MySQL manager or server"; echo fi ;; @@ -319,32 +360,32 @@ # Stop daemon. We use a signal here to avoid having to know the # root password. - # The RedHat / SuSE lock directory to remove + # The Mandriva Linux lock directory to remove lock_dir=/var/lock/subsys/mysqlmanager # If the manager pid_file doesn't exist, try the server's if test ! -s "$pid_file" then pid_file=$server_pid_file - lock_dir=/var/lock/subsys/mysql + lock_dir=/var/lock/subsys/mysqld fi if test -s "$pid_file" then mysqlmanager_pid=`cat $pid_file` - echo $echo_n "Shutting down MySQL" + echo $echo_n "Shutting down MySQL: " kill $mysqlmanager_pid # mysqlmanager should remove the pid_file when it exits, so wait for it. - wait_for_pid removed; return_value=$? + wait_for_pid removed; return_value=$?; echo # delete lock for RedHat / SuSE if test -f $lock_dir then - rm -f $lock_dir + rm -f $lock_dir /var/lock/subsys/mysqld fi exit $return_value else - log_failure_msg "MySQL manager or server PID file could not be found!" + log_failure_msg "MySQL manager or server PID file could not be found!"; echo fi ;; @@ -363,9 +404,9 @@ if test -s "$server_pid_file" ; then read mysqld_pid < $server_pid_file kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" - touch $server_pid_file + touch $server_pid_file; 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 ;; @@ -387,7 +428,7 @@ if test "$use_mysqld_safe" = "0" ; then lockfile=/var/lock/subsys/mysqlmanager else - lockfile=/var/lock/subsys/mysql + lockfile=/var/lock/subsys/mysqld fi if test -f $lockfile ; then log_failure_msg "MySQL is not running, but lock exists"