#!/bin/sh # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB # This file is public domain and comes with NO WARRANTY of any kind # MySQL daemon start/stop script. # # chkconfig: 2345 92 22 # description: Starts and stops mysql 5 # Source function library. . /etc/init.d/functions basedir= # The following variables are only set for letting mysql.server find things. # Set some defaults datadir=/dbroot/mysql/5.0.0-alpha/data ## Customizations START (added by Anand Sharma) defaultsfile=/etc/mysql/5.0.0-alpha/my.cnf logdir=/dbroot/mysql/5.0.0-alpha/logs piddir=/dbroot/mysql/5.0.0-alpha/var errlog=$logdir/error.log # use --log-error binlog=$logdir/binary.log # use --log-bin= slowqrslog=$logdir/slowqueries.log # use --log-slow-queries ## Customizations END pid_file= if test -z "$basedir" then basedir=/usr/local/mysql/5.0.0-alpha bindir=/usr/local/mysql/5.0.0-alpha/bin else bindir="$basedir/bin" fi PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin export PATH mode=$1 # start or stop 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 } # Get arguments from the my.cnf file, # groups [mysqld] [mysql_server] and [mysql.server] 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 # Try to find basedir in /etc/my.cnf conf=/etc/my.cnf print_defaults= if test -r $conf then subpat='^[^=]*basedir[^=]*=\(.*\)$' dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf` for d in $dirs do d=`echo $d | sed -e 's/[ ]//g'` if test -x "$d/bin/my_print_defaults" then print_defaults="$d/bin/my_print_defaults" break fi if test -x "$d/bin/mysql_print_defaults" then print_defaults="$d/bin/mysql_print_defaults" break fi done fi # Hope it's in the PATH ... but I doubt it test -z "$print_defaults" && print_defaults="my_print_defaults" fi # # Test if someone changed datadir; In this case we should also read the # default arguments from this directory # extra_args="" if test "$datadir" != "/dbroot/mysql/5.0.0-alpha/data" then extra_args="-e $datadir/my.cnf" fi parse_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server` # # Set pid file if not given # if test -z "$pid_file" then pid_file=$piddir/`/bin/hostname`.pid else case "$pid_file" in /* ) ;; * ) pid_file="$piddir/$pid_file" ;; esac fi # Safeguard (relative paths, core dumps..) cd $basedir case "$mode" in 'start') # Start daemon 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 --defaults-file=$defaultsfile --datadir=$datadir --pid-file=$pid_file --log-error=$errlog --log-bin=$binlog --log-slow-queries=$slowqrslog & # Make lock for RedHat / SuSE if test -w /var/lock/subsys then touch /var/lock/subsys/mysql5 fi else echo "Can't execute $bindir/mysqld_safe from dir $basedir" fi ;; 'stop') # Stop daemon. We use a signal here to avoid having to know the # root password. if test -s "$pid_file" then mysqld_pid=`cat $pid_file` echo "Killing mysqld with pid $mysqld_pid" kill $mysqld_pid # mysqld should remove the pid_file when it exits, so wait for it. sleep 1 while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ] do [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c" flags=a$flags sleep 1 done if [ -s $pid_file ] then echo " gave up waiting!" elif [ -n "$flags" ] then echo " done" fi # delete lock for RedHat / SuSE if test -f /var/lock/subsys/mysql5 then rm -f /var/lock/subsys/mysql5 fi else echo "No mysqld pid file found. Looked for $pid_file." fi ;; 'restart') # Stop the service and regardless of whether it was # running or not, start it again. $0 stop $0 start ;; *) # usage echo "Usage: $0 start|stop|restart" exit 1 ;; esac