home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / init.d / mysql < prev    next >
Text File  |  2006-09-13  |  8KB  |  279 lines

  1. #!/bin/sh
  2. # Copyright (c) 1995-2002 SuSE Linux AG Nuernberg, Germany.
  3. #
  4. # Author: Lenz Grimmer <feedback@suse.de>
  5. #
  6. # /etc/init.d/mysql
  7. #
  8. #   and its symbolic link
  9. #
  10. # /usr/sbin/rcmysql
  11. #
  12. ### BEGIN INIT INFO
  13. # Provides:       mysql
  14. # Required-Start: $network $remote_fs
  15. # Required-Stop:
  16. # Default-Start:  2 3 5
  17. # Default-Stop:
  18. # Description:    Start the MySQL database server
  19. ### END INIT INFO
  20.  
  21. # Shell functions sourced from /etc/rc.status:
  22. #      rc_check         check and set local and overall rc status
  23. #      rc_status        check and set local and overall rc status
  24. #      rc_status -v     ditto but be verbose in local rc status
  25. #      rc_status -v -r  ditto and clear the local rc status
  26. #      rc_failed        set local and overall rc status to failed
  27. #      rc_failed <num>  set local and overall rc status to <num>
  28. #      rc_reset         clear local rc status (overall remains)
  29. #      rc_exit          exit appropriate to overall rc status
  30. . /etc/rc.status
  31.  
  32. # First reset status of this service
  33. rc_reset
  34.  
  35. # Return values acc. to LSB for all commands but status:
  36. # 0 - success
  37. # 1 - generic or unspecified error
  38. # 2 - invalid or excess argument(s)
  39. # 3 - unimplemented feature (e.g. "reload")
  40. # 4 - insufficient privilege
  41. # 5 - program is not installed
  42. # 6 - program is not configured
  43. # 7 - program is not running
  44. # Note that starting an already running service, stopping
  45. # or restarting a not-running service as well as the restart
  46. # with force-reload (in case signalling is not supported) are
  47. # considered a success.
  48.  
  49. # Test, if mysqld or mysql-max actually exist
  50. unset MYSQLD
  51. if test -x /usr/sbin/mysqld-max
  52. then
  53.         MYSQLD=/usr/sbin/mysqld-max
  54. elif test -x /usr/sbin/mysqld
  55. then
  56.         MYSQLD=/usr/sbin/mysqld
  57. fi
  58. test "$MYSQLD" || { echo "Nor /usr/sbin/mysqld nor /usr/sbin/mysqld-max exists"; rc_failed 5; rc_status -v; rc_exit; }
  59.  
  60. # The following section has been taken from
  61. # the original MySQL init script
  62. basedir=/usr
  63. datadir=/var/lib/mysql
  64. mysql_daemon_user=mysql
  65. mysql_daemon_group=mysql
  66. pid_file=/var/lib/mysql/mysqld.pid
  67. socket=/var/lib/mysql/mysql.sock
  68. MYADMIN=/usr/bin/mysqladmin
  69. export TMPDIR=/var/lib/mysql/tmp
  70. if test -z "$basedir"
  71. then
  72.   basedir=/usr
  73.   bindir=/usr/bin
  74. else
  75.   bindir="$basedir/bin"
  76. fi
  77.  
  78. if test -z "$pid_file"
  79. then
  80.   pid_file=$datadir/`/bin/hostname`.pid
  81. else
  82.   case "$pid_file" in
  83.     /* ) ;;
  84.     * )  pid_file="$datadir/$pid_file" ;;
  85.   esac
  86. fi
  87.  
  88. mode=$1 # start or stop
  89.  
  90. parse_arguments() {
  91.   for arg do
  92.     case "$arg" in
  93.       --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  94.       --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  95.       --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  96.       --socket=*)   socket=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  97.     esac
  98.   done
  99. }
  100.  
  101. # Get arguments from the my.cnf file, groups [mysqld] and [mysql_server]
  102. if test -x ./bin/my_print_defaults
  103. then
  104.   print_defaults="./bin/my_print_defaults"
  105. elif test -x $bindir/my_print_defaults
  106. then
  107.   print_defaults="$bindir/my_print_defaults"
  108. elif test -x $bindir/mysql_print_defaults
  109. then
  110.   print_defaults="$bindir/mysql_print_defaults"
  111. else
  112.   # Try to find basedir in /etc/my.cnf
  113.   conf=/etc/my.cnf
  114.   print_defaults=
  115.   if test -r $conf
  116.   then
  117.     subpat='^[^=]*basedir[^=]*=\(.*\)$'
  118.     dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
  119.     for d in $dirs
  120.     do
  121.       d=`echo $d | sed -e 's/[     ]//g'`
  122.       if test -x "$d/bin/my_print_defaults"
  123.       then
  124.         print_defaults="$d/bin/my_print_defaults"
  125.         break
  126.       fi
  127.       if test -x "$d/bin/mysql_print_defaults"
  128.       then
  129.         print_defaults="$d/bin/mysql_print_defaults"
  130.         break
  131.       fi
  132.     done
  133.   fi
  134.  
  135.   # Hope it's in the PATH ... but I doubt it
  136.   test -z "$print_defaults" && print_defaults="my_print_defaults"
  137. fi
  138.  
  139. parse_arguments `$print_defaults $defaults mysqld mysql_server`
  140.  
  141. # Safeguard (relative paths, core dumps..)
  142. cd $basedir
  143.  
  144. case "$1" in
  145.     start)
  146.     # exit gracefully, if we are already running
  147.     checkproc $MYSQLD && echo -n "Starting service MySQL " && \
  148.     rc_status -v && rc_exit
  149.  
  150.     # Test, if safe_mysqld actually exists
  151.     SAFE_MYSQLD=/usr/bin/mysqld_safe
  152.     test -x $SAFE_MYSQLD || { echo "$SAFE_MYSQLD does not exist "; rc_failed 5; rc_status -v; rc_exit; }
  153.  
  154.     # check for ISAM tables
  155.     tables=`find $datadir -name '*.ISM' | sed "s@$datadir/*@@; s@.ISM@@; s@/@.@;"`
  156.     if test "$tables" ; then
  157.         echo
  158.         echo "Some tables still use ISAM format, please convert them to something "
  159.         echo "better (eg. MyISAM). ISAM support will be dropped in future releases. "
  160.         echo "You can use mysql_convert_table_format script to do this conversion. "
  161.         echo
  162.         echo "Tables using ISAM are: "
  163.         echo "  $tables "
  164.         echo
  165.     fi
  166.  
  167.     # this file was used in past, but it's batter to place it youtside database directory
  168.     if test -f $datadir/mysql/stamp-4.1 ; then
  169.         rm $datadir/mysql/stamp-4.1
  170.     fi
  171.  
  172.     # We assume a fresh install if the directory $datadir/mysql
  173.     # does not exist and create the privilege database
  174.     if ! ls $datadir/update-stamp-* >/dev/null 2>&1 ; then
  175.         echo "Creating/Updating MySQL privilege database... "
  176.         mysql_install_db --user=$mysql_daemon_user --datadir=$datadir || rc_failed
  177.     fi
  178.     if test ! -f $datadir/update-stamp-5.0 ; then
  179.         echo "Updating MySQL privilege database... "
  180.  
  181.     echo "Fixing privilege tables... "
  182.         (echo 'USE mysql;'; cat /usr/share/mysql/mysql_fix_privilege_tables.sql) \
  183.         | sed '/^---\? /D; s/#.*//; s/;$/#/' | tr '\n' ' ' | tr '#' '\n' \
  184.         | /usr/sbin/mysqld \
  185.             --bootstrap \
  186.             --skip-innodb \
  187.             --skip-bdb \
  188.             --skip-grant-tables \
  189.             --user=$mysql_daemon_user \
  190.             --pid-file=$pid_file \
  191.             --socket=$socket \
  192.             --datadir=$datadir 2>/dev/null
  193.  
  194.     rm -f $datadir/update-stamp-4.1
  195.     touch $datadir/update-stamp-5.0
  196.         
  197.         # Fix ownerships and permissions for $datadir
  198.         chmod 755 $datadir
  199.         chown -R $mysql_daemon_user.$mysql_daemon_group $datadir
  200.     fi
  201.  
  202.     echo -n "Starting service MySQL "
  203.  
  204.     $SAFE_MYSQLD \
  205.         --user=$mysql_daemon_user \
  206.         --pid-file=$pid_file \
  207.         --socket=$socket \
  208.         --datadir=$datadir &>/dev/null &
  209.  
  210.     for((i=0; i<50; i++)); do
  211.        sleep 0.2
  212.            test -S $socket && i='' && break
  213.         done
  214.  
  215.     test -z "$i" || rc_failed
  216.  
  217.     # Rmember status and be verbose
  218.     rc_status -v
  219.     ;;
  220.  
  221.     stop)
  222.     echo -n "Shutting down service MySQL "
  223.     killproc -p $pid_file -TERM $MYSQLD
  224.  
  225.     # Remember status and be verbose
  226.     rc_status -v
  227.     ;;
  228.  
  229.     try-restart)
  230.     ## Stop the service and if this succeeds (i.e. the 
  231.     ## service was running before), start it again.
  232.     ## Note: try-restart is not (yet) part of LSB (as of 0.7.5)
  233.     $0 status >/dev/null &&  $0 restart
  234.  
  235.     # Remember status and be quiet
  236.     rc_status
  237.     ;;
  238.  
  239.     restart|force-reload)
  240.     echo "Restarting service MySQL "
  241.     $0 stop
  242.     $0 start
  243.  
  244.     rc_status
  245.     ;;
  246.  
  247.     reload)
  248.     echo -n "Reloading service MySQL "
  249.     killproc -p $pid_file -HUP $MYSQLD
  250.     touch $pid_file
  251.     rc_status -v
  252.     ;;
  253.     
  254.     check|status)
  255.     echo -n "Checking for service MySQL: "
  256.     ## Check status with checkproc(8), if process is running
  257.     ## checkproc will return with exit status 0.
  258.  
  259.     # Status has a slightly different for the status command:
  260.     # 0 - service running
  261.     # 1 - service dead, but /var/run/  pid  file exists
  262.     # 2 - service dead, but /var/lock/ lock file exists
  263.     # 3 - service not running
  264.  
  265.     # NOTE: checkproc returns LSB compliant status values.
  266.     checkproc $MYSQLD
  267.     rc_status -v
  268.     ;;
  269.  
  270.     *)
  271.     echo "Usage: $0 {start|stop|status|reload|restart|try-restart|force-reload}"
  272.     exit 1
  273.     ;;
  274. esac
  275. rc_exit
  276.  
  277. # vim: ft=sh
  278.