home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / MySql / support-files / mysql.server.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2001-01-01  |  3.9 KB  |  156 lines

  1. #!/bin/sh
  2. # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
  3. # This file is public domain and comes with NO WARRANTY of any kind
  4.  
  5. # Mysql daemon start/stop script.
  6.  
  7. # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
  8. # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/S01mysql.
  9. # When this is done the mysql server will be started when the machine is
  10. # started and shut down when the systems goes down.
  11.  
  12. # Comments to support chkconfig on RedHat Linux
  13. # chkconfig: 2345 90 90
  14. # description: A very fast and reliable SQL database engine.
  15.  
  16. # The following variables are only set for letting mysql.server find things.
  17. # If you want to affect other MySQL variables, you should make your changes
  18. # in the /etc/my.cnf or other configuration files.
  19.  
  20. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  21. export PATH
  22.  
  23. # Set some defaults
  24. datadir=@localstatedir@
  25. basedir=
  26. pid_file=
  27. if test -z "$basedir"
  28. then
  29.   basedir=@prefix@
  30.   bindir=@bindir@
  31. else
  32.   bindir="$basedir/bin"
  33. fi
  34. if test -z "$pid_file"
  35. then
  36.   pid_file=$datadir/`@HOSTNAME@`.pid
  37. else
  38.   case "$pid_file" in
  39.     /* ) ;;
  40.     * )  pid_file="$datadir/$pid_file" ;;
  41.   esac
  42. fi
  43.  
  44. mode=$1    # start or stop
  45.  
  46. parse_arguments() {
  47.   for arg do
  48.     case "$arg" in
  49.       --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  50.       --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  51.       --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  52.     esac
  53.   done
  54. }
  55.  
  56. # Get arguments from the my.cfg file, groups [mysqld] and [mysql_server]
  57. if test -x ./bin/my_print_defaults
  58. then
  59.   print_defaults="./bin/my_print_defaults"
  60. elif test -x $bindir/my_print_defaults
  61. then
  62.   print_defaults="$bindir/my_print_defaults"
  63. elif test -x $bindir/mysql_print_defaults
  64. then
  65.   print_defaults="$bindir/mysql_print_defaults"
  66. else
  67.   # Try to find basedir in /etc/my.cnf
  68.   conf=/etc/my.cnf
  69.   print_defaults=
  70.   if test -r $conf
  71.   then
  72.     subpat='^[^=]*basedir[^=]*=\(.*\)$'
  73.     dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
  74.     for d in $dirs
  75.     do
  76.       d=`echo $d | sed -e 's/[     ]//g'`
  77.       if test -x "$d/bin/my_print_defaults"
  78.       then
  79.         print_defaults="$d/bin/my_print_defaults"
  80.         break
  81.       fi
  82.       if test -x "$d/bin/mysql_print_defaults"
  83.       then
  84.         print_defaults="$d/bin/mysql_print_defaults"
  85.         break
  86.       fi
  87.     done
  88.   fi
  89.  
  90.   # Hope it's in the PATH ... but I doubt it
  91.   test -z "$print_defaults" && print_defaults="my_print_defaults"
  92. fi
  93.  
  94. parse_arguments `$print_defaults $defaults mysqld mysql_server`
  95.  
  96. # Safeguard (relative paths, core dumps..)
  97. cd $basedir
  98.  
  99. case "$mode" in
  100.   'start')
  101.     # Start daemon
  102.  
  103.     if test -x $bindir/safe_mysqld
  104.     then
  105.       # Give extra arguments to mysqld with the my.cnf file. This script may
  106.       # be overwritten at next upgrade.
  107.       $bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &
  108.       # Make lock for RedHat / SuSE
  109.       if test -w /var/lock/subsys
  110.       then
  111.         touch /var/lock/subsys/mysql
  112.       fi
  113.     else
  114.       echo "Can't execute $bindir/safe_mysqld"
  115.     fi
  116.     ;;
  117.  
  118.   'stop')
  119.     # Stop daemon. We use a signal here to avoid having to know the
  120.     # root password.
  121.     if test -f "$pid_file"
  122.     then
  123.       mysqld_pid=`cat $pid_file`
  124.       echo "Killing mysqld with pid $mysqld_pid"
  125.       kill $mysqld_pid
  126.       # mysqld should remove the pid_file when it exits, so wait for it.
  127.  
  128.       sleep 1
  129.       while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
  130.       do
  131.         [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
  132.         flags=a$flags
  133.         sleep 1
  134.       done
  135.       if [ -s $pid_file ]
  136.          then echo " gave up waiting!"
  137.       elif [ -n "$flags" ]
  138.          then echo " done"
  139.       fi
  140.       # delete lock for RedHat / SuSE
  141.       if test -f /var/lock/subsys/mysql
  142.       then
  143.         rm /var/lock/subsys/mysql
  144.       fi
  145.     else
  146.       echo "No mysqld pid file found. Looked for $pid_file."
  147.     fi
  148.     ;;
  149.  
  150.   *)
  151.     # usage
  152.     echo "usage: $0 start|stop"
  153.     exit 1
  154.     ;;
  155. esac
  156.