diff options
Diffstat (limited to 'support-files/mysql.server.sh')
-rw-r--r-- | support-files/mysql.server.sh | 84 |
1 files changed, 65 insertions, 19 deletions
diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index 7f4987be3a8..150a8a151ba 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -10,7 +10,7 @@ # started and shut down when the systems goes down. # Comments to support chkconfig on RedHat Linux -# chkconfig: 2345 90 20 +# chkconfig: 2345 64 36 # description: A very fast and reliable SQL database engine. # Comments to support LSB init script conventions @@ -54,6 +54,23 @@ else bindir="$basedir/bin" fi +# +# Use LSB init script functions for printing messages, if possible +# +lsb_functions="/lib/lsb/init-functions" +if test -f $lsb_functions ; then + source $lsb_functions +else + log_success_msg() + { + echo " SUCCESS! $@" + } + log_failure_msg() + { + echo " ERROR! $@" + } +fi + PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin export PATH @@ -75,6 +92,33 @@ parse_arguments() { done } +wait_for_pid () { + i=0 + while test $i -lt 35 ; do + sleep 1 + case "$1" in + 'created') + test -s $pid_file && i='' && break + ;; + 'removed') + test ! -s $pid_file && i='' && break + ;; + *) + echo "wait_for_pid () usage: wait_for_pid created|removed" + exit 1 + ;; + esac + echo $echo_n ".$echo_c" + i=`expr $i + 1` + done + + if test -z "$i" ; then + log_success_msg + else + log_failure_msg + fi +} + # Get arguments from the my.cnf file, # groups [mysqld] [mysql_server] and [mysql.server] if test -x ./bin/my_print_defaults @@ -125,7 +169,7 @@ then extra_args="-e $datadir/my.cnf" fi -parse_arguments `$print_defaults $extra_args mysqld mysql_server mysql.server` +parse_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server` # # Set pid file if not given @@ -151,14 +195,17 @@ case "$mode" in then # Give extra arguments to mysqld with the my.cnf file. This script may # be overwritten at next upgrade. + echo $echo_n "Starting MySQL" $bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file >/dev/null 2>&1 & + wait_for_pid created + # Make lock for RedHat / SuSE if test -w /var/lock/subsys then touch /var/lock/subsys/mysql fi else - echo "Can't execute $bindir/mysqld_safe from dir $basedir" + log_failure_msg "Can't execute $bindir/mysqld_safe" fi ;; @@ -168,29 +215,18 @@ case "$mode" in if test -s "$pid_file" then mysqld_pid=`cat $pid_file` - echo "Killing mysqld with pid $mysqld_pid" + echo $echo_n "Shutting down MySQL" kill $mysqld_pid # mysqld should remove the pid_file when it exits, so wait for it. + wait_for_pid removed - sleep 1 - while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ] - do - [ -z "$flags" ] && echo $echo_n "Wait for mysqld to exit$echo_c" || echo $echo_n ".$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/mysql then rm -f /var/lock/subsys/mysql fi else - echo "No mysqld pid file found. Looked for $pid_file." + log_failure_msg "MySQL PID file could not be found!" fi ;; @@ -199,11 +235,21 @@ case "$mode" in # running or not, start it again. $0 stop $0 start - ;; + ;; + + 'reload') + if test -s "$pid_file" ; then + mysqld_pid=`cat $pid_file` + kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" + touch $pid_file + else + log_failure_msg "MySQL PID file could not be found!" + fi + ;; *) # usage - echo "Usage: $0 start|stop|restart" + echo "Usage: $0 start|stop|restart|reload" exit 1 ;; esac |