Commit 7f877deb authored by tim@threads.polyesthetic.msg's avatar tim@threads.polyesthetic.msg
Browse files

Clean up safe_mysqld, mysql_install_db and mysql.server. They

should now work the way you expect them to (process command-line
arguments consistently).
parent 0c94c1de
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -38966,6 +38966,11 @@ though, so Version 3.23 is not released as a stable version yet.
@appendixsubsec Changes in release 3.23.29
@itemize @bullet
@item
safe_mysqld, mysql.server and mysql_install_db have been modified
to use mysql_print_defaults instead of various hacks to read the
my.cnf files.  In addition, the handling of various paths has been
made more consistent with how mysqld handles them by default.
@item
Automatically remove Berkeley DB transaction logs that are no longer in
use.
@item
+80 −84
Original line number Diff line number Diff line
#!/bin/sh
# Copyright (C) 1997, 1998, 1999 TCX DataKonsult AB & Monty Program KB & Detron HB
# For a more info consult the file COPYRIGHT distributed with this file
# For a more info consult the file COPYRIGHT distributed with this file.

# This scripts creates the privilege tables db, host, user, tables_priv,
# columns_priv in the mysql database, as well as the func table.
#
# All arguments (exept -IN-RPM as a first argument) to this script are
# passed to mysqld
# All unrecognized arguments to this script are passed to mysqld.

ldata=@localstatedir@
execdir=@libexecdir@
bindir=@bindir@
sbindir=@sbindir@
force=0
IN_RPM=0
defaults=

while [ "x$1" != x ]
do
case "$1" in
   -*) eqvalue="`echo $1 |sed 's/[-_a-zA-Z0-9]*=//'`"
       case "$1" in
       -IN-RPM) IN_RPM=1
                ;;
       --force) force=1
                ;;
       --no-defaults)     defaults="$1"; CONFIG_FILES=/nonexistent
                ;;
       --defaults-file=*) defaults="$1"; CONFIG_FILES="$eqvalue"
                ;;
       --basedir=*) SETVARS="$SETVARS basedir=\"$eqvalue\"; bindir=\"$eqvalue/bin\"; execdir=\"$eqvalue/libexec\"; sbindir=\"$eqvalue/sbin\"; "
                ;;
       --ldata=*|--datadir=*) SETVARS="$SETVARS ldata=\"$eqvalue\";"
                ;;
       --user=*) SETVARS="$SETVARS user=\"$eqvalue\";"
    -IN-RPM)
      IN_RPM="$1"; shift
      ;;
esac
defaults=
case "$1" in
    --no-defaults|--defaults-file=*|--defaults-extra-file=*)
      defaults="$1"; shift
      ;;
esac
   shift
done
             
GetCNF () {

VARIABLES="basedir bindir datadir sbindir user pid-file log port socket"
# set it not already set
CONFIG_FILES=${CONFIG_FILES:-"/etc/my.cnf ./my.cnf $HOME/.my.cnf"}

for c in $CONFIG_FILES
do
   if [ -f $c ]
parse_arguments() {
  # We only need to pass arguments through to the server if we don't
  # handle them here.  So, we collect unrecognized options (passed on
  # the command line) into the args variable.
  pick_args=
  if test "$1" = PICK-ARGS-FROM-ARGV
  then
      #echo "Processing $c..."
      for v in $VARIABLES
      do
         # This method assumes last of duplicate $variable entries will be the
         # value set ([mysqld])
         # This could easily be rewritten to gather [xxxxx]-specific entries,
         # but for now it looks like only the mysqld ones are needed for
         # server startup scripts
         thevar=""
         eval `sed -n -e '/^$/d' -e '/^#/d' -e 's,[ 	],,g' -e '/=/p' $c |\
         awk -F= -v v=$v '{if ($1 == v) printf ("thevar=\"%s\"\n", $2)}'`

         # it would be easier if the my.cnf and variable values were
         # all matched, but since they aren't we need to map them here.
         case $v in
         pid-file) v=pid_file ;;
              log) v=log_file ;;
          datadir) v=ldata ;;
         esac

         # As long as $thevar isn't blank, use it to set or override current
         # value
         [ "$thevar" != "" ] && eval $v=$thevar
    pick_args=1
    shift
  fi

      done
   #else
   #   echo "No $c config file."
  for arg do
    case "$arg" in
      --force) force=1 ;;
      --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --ldata=*|--datadir=*) ldata=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      *)
        if test -n "$pick_args"
        then
          # This sed command makes sure that any special chars are quoted,
          # so the arg gets passed exactly to the server.
          args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'`
        fi
        ;;
    esac
  done
}

# run function to get config values
GetCNF
# Get first arguments from the my.cfg file, groups [mysqld] and
# [mysql_install_db], and then merge with the command line arguments
if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x @bindir@/my_print_defaults
then
  print_defaults="@bindir@/my_print_defaults"
elif test -x @bindir@/mysql_print_defaults
then
  print_defaults="@bindir@/mysql_print_defaults"
else
  print_defaults="my_print_defaults"
fi

# Override/set with command-line values
eval $SETVARS
args=
ldata=
execdir=
bindir=
basedir=
force=0
parse_arguments `$print_defaults $defaults mysqld mysql_install_db`
parse_arguments PICK-ARGS-FROM-ARGV "$@"

test -z "$ldata" && ldata=@localstatedir@
if test -z "$basedir"
then
  basedir=@prefix@
  bindir=@bindir@
  execdir=@libexecdir@ 
else
  bindir="$basedir/bin"
  execdir="$basedir/libexec"
fi

mdata=$ldata/mysql

@@ -151,7 +146,7 @@ c_t="" c_c=""
# Check for old tables
if test ! -f $mdata/db.frm
then
  echo "Creating db table"
  echo "Preparing db table"

  # mysqld --bootstrap wants one command/line
  c_d="$c_d CREATE TABLE db ("
@@ -179,7 +174,7 @@ fi

if test ! -f $mdata/host.frm
then
  echo "Creating host table"
  echo "Preparing host table"

  c_h="$c_h CREATE TABLE host ("
  c_h="$c_h  Host char(60) DEFAULT '' NOT NULL,"
@@ -201,7 +196,7 @@ fi

if test ! -f $mdata/user.frm
then
  echo "Creating user table"
  echo "Preparing user table"

  c_u="$c_u CREATE TABLE user ("
  c_u="$c_u   Host char(60) DEFAULT '' NOT NULL,"
@@ -237,7 +232,7 @@ fi

if test ! -f $mdata/func.frm
then
  echo "Creating func table"
  echo "Preparing func table"

  c_f="$c_f CREATE TABLE func ("
  c_f="$c_f   name char(64) DEFAULT '' NOT NULL,"
@@ -251,7 +246,7 @@ fi

if test ! -f $mdata/tables_priv.frm
then
  echo "Creating tables_priv table"
  echo "Preparing tables_priv table"

  c_t="$c_t CREATE TABLE tables_priv ("
  c_t="$c_t   Host char(60) DEFAULT '' NOT NULL,"
@@ -270,7 +265,7 @@ fi

if test ! -f $mdata/columns_priv.frm
then
  echo "Creating columns_priv table"
  echo "Preparing columns_priv table"

  c_c="$c_c CREATE TABLE columns_priv ("
  c_c="$c_c   Host char(60) DEFAULT '' NOT NULL,"
@@ -285,8 +280,9 @@ then
  c_c="$c_c   comment='Column privileges';"
fi

 if $execdir/mysqld $defaults --bootstrap --skip-grant-tables \
    --basedir=@prefix@ --datadir=$ldata "$@" << END_OF_DATA
echo "Installing all prepared tables"
if eval "$execdir/mysqld $defaults --bootstrap --skip-grant-tables \
         --basedir=$basedir --datadir=$ldata $args" << END_OF_DATA
use mysql;
$c_d
$i_d
+9 −1
Original line number Diff line number Diff line
@@ -118,7 +118,15 @@ then
  exit 1
fi

test -z "$pid_file" && pid_file=$DATADIR/`@HOSTNAME@`.pid
if test -z "$pid_file"
then
  pid_file=$DATADIR/`@HOSTNAME@`.pid
else
  case "$pid_file" in
    /* ) ;;
    * )  pid_file="$DATADIR/$pid_file" ;;
  esac
fi
test -z "$err_log"  && err_log=$DATADIR/`@HOSTNAME@`.err

export MYSQL_UNIX_PORT
+57 −59
Original line number Diff line number Diff line
@@ -4,71 +4,70 @@

# Mysql daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4
# based systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/S01mysql.
# When this is done the mysql server will be started when the machine is started
# and shut down when the systems goes down.
# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/S01mysql.
# 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 90 90
# description: A very fast and reliable SQL database engine.

# The following variables are only set for letting mysql.server find things
# if you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf or other configuration files
# The following variables are only set for letting mysql.server find things.
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf or other configuration files.

PATH=/sbin:/usr/sbin:/bin:/usr/bin
basedir=@prefix@
bindir=@bindir@
sbindir=@sbindir@
datadir=@localstatedir@
pid_file=@localstatedir@/mysqld.pid

export PATH

mode=$1

GetCNF () {

VARIABLES="basedir bindir sbindir datadir pid-file"
CONFIG_FILES="/etc/my.cnf $basedir/my.cnf $HOME/.my.cnf"
parse_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
    esac
  done
}

for c in $CONFIG_FILES
do
   if [ -f $c ]
# Get arguments from the my.cfg file, group [mysqld]
if test -x ./bin/my_print_defaults
then
      #echo "Processing $c..."
      for v in $VARIABLES
      do
         # This method assumes last of duplicate $variable entries will be the
         # value set ([mysqld])
         # This could easily be rewritten to gather [xxxxx]-specific entries,
         # but for now it looks like only the mysqld ones are needed for
         # server startup scripts
         thevar=""
         eval `sed -n -e '/^$/d' -e '/^#/d' -e 's,[ 	],,g' -e '/=/p' $c |\
         awk -F= -v v=$v '{if ($1 == v) printf ("thevar=\"%s\"\n", $2)}'`

         # it would be easier if the my.cnf and variable values were
         # all matched, but since they aren't we need to map them here.
         case $v in
         pid-file) v=pid_file ;;
              log) v=log_file ;;
         esac
  print_defaults="./bin/my_print_defaults"
elif test -x @bindir@/my_print_defaults
then
  print_defaults="@bindir@/my_print_defaults"
elif test -x @bindir@/mysql_print_defaults
then
  print_defaults="@bindir@/mysql_print_defaults"
else
  print_defaults="my_print_defaults"
fi

         # As long as $thevar isn't blank, use it to set or override current
         # value
         [ "$thevar" != "" ] && eval $v=$thevar
datadir=@localstatedir@
basedir=
pid_file=
parse_arguments `$print_defaults $defaults mysqld mysql_server`

      done
   #else
   #   echo "No $c config file."
if test -z "$basedir"
then
  basedir=@prefix@
  bindir=@bindir@
else
  bindir="$basedir/bin"
fi
if test -z "$pid_file"
then
  pid_file=$datadir/mysqld.pid
else
  case "$pid_file" in
    /* ) ;;
    * )  pid_file="$datadir/$pid_file" ;;
  esac
fi
done
}

# run function to get config values
GetCNF

# Safeguard (relative paths, core dumps..)
cd $basedir
@@ -81,8 +80,7 @@ case "$mode" in
    then
      # Give extra arguments to mysqld with the my.cnf file. This script may
      # be overwritten at next upgrade.
      $bindir/safe_mysqld \
	--datadir=$datadir --pid-file=$pid_file &
      $bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &
      # Make lock for RedHat / SuSE
      if test -d /var/lock/subsys
      then
@@ -115,7 +113,7 @@ case "$mode" in
         then echo " done"
      fi
      # delete lock for RedHat / SuSE
      if test -d /var/lock/subsys
      if test -e /var/lock/subsys/mysql
      then
        rm /var/lock/subsys/mysql
      fi