home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / mysql / mysql.server.z / mysql.server
Encoding:
Text File  |  1999-10-18  |  2.7 KB  |  103 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
  8. # based systems) and linked to /etc/rc3.d/S99mysql. When this is done
  9. # the mysql server will be started when the machine is started.
  10.  
  11. # Comments to support chkconfig on RedHat Linux
  12. # chkconfig: 2345 90 90
  13. # description: A very fast and reliable SQL database engine.
  14.  
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. basedir=/usr/freeware
  17. bindir=/usr/freeware/bin
  18. pid_file=/var/spool/mysql/mysqld.pid
  19. mysql_daemon_user=root    # Run mysqld as this user.
  20. export PATH
  21.  
  22. mode=$1
  23.  
  24. if test -w /             # determine if we should look at the root config file
  25. then                     # or user config file
  26.   conf=/etc/my.cnf
  27. else
  28.   conf=$HOME/.my.cnf    # Using the users config file
  29. fi
  30.  
  31. # The following code tries to get the variables safe_mysqld needs from the
  32. # config file.  This isn't perfect as this ignores groups, but it should
  33. # work as the options doesn't conflict with anything else.
  34.  
  35. if test -f "$conf"       # Extract those fields we need from config file.
  36. then
  37.   if grep "^datadir" $conf >/dev/null
  38.   then
  39.     datadir=`grep "^datadir" $conf | cut -f 2 -d= | tr -d ' '`
  40.   fi
  41.   if grep "^user" $conf >/dev/null
  42.   then
  43.     mysql_daemon_user=`grep "^user" $conf | cut -f 2 -d= | tr -d ' '`
  44.   fi
  45.   if grep "^pid-file" $conf >/dev/null
  46.   then
  47.     pid_file=`grep "^pid-file" $conf | cut -f 2 -d= | tr -d ' '`
  48.   else
  49.     if test -d "$datadir"
  50.     then
  51.       pid_file=$datadir/`hostname`.pid
  52.     fi
  53.   fi
  54.   if grep "^basedir" $conf >/dev/null
  55.   then
  56.     basedir=`grep "^basedir" $conf | cut -f 2 -d= | tr -d ' '`
  57.     bindir=$basedir/bin
  58.   fi
  59.   if grep "^bindir" $conf >/dev/null
  60.   then
  61.     bindir=`grep "^bindir" $conf | cut -f 2 -d=| tr -d ' '`
  62.   fi
  63. fi
  64.  
  65.  
  66. # Safeguard (relative paths, core dumps..)
  67. cd $basedir
  68.  
  69. case "$mode" in
  70.   'start')
  71.     # Start daemon
  72.  
  73.     if test -x $bindir/safe_mysqld
  74.     then
  75.       # Give extra arguments to mysqld with the my.cnf file. This script may
  76.       # be overwritten at next upgrade.
  77.       $bindir/safe_mysqld --user=$mysql_daemon_user --pid-file=$pid_file &
  78.     else
  79.       echo "Can't execute $bindir/safe_mysqld"
  80.     fi
  81.     ;;
  82.  
  83.   'stop')
  84.     # Stop daemon. We use a signal here to avoid having to know the
  85.     # root password.
  86.     if test -f "$pid_file"
  87.     then
  88.       mysqld_pid=`cat $pid_file`
  89.       echo "Killing mysqld with pid $mysqld_pid"
  90.       kill $mysqld_pid
  91.       # mysqld should remove the pid_file when it exits.
  92.     else
  93.       echo "No mysqld pid file found. Looked for $pid_file."
  94.     fi
  95.     ;;
  96.  
  97.   *)
  98.     # usage
  99.     echo "usage: $0 start|stop"
  100.     exit 1
  101.     ;;
  102. esac
  103.