2000-07-31 21:29:14 +02:00
#!/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
#
2007-05-05 03:06:36 +02:00
# Script to start the MySQL daemon and restart it if it dies unexpectedly
2000-07-31 21:29:14 +02:00
#
# This should be executed in the MySQL base directory if you are using a
2007-05-05 03:06:36 +02:00
# binary installation that is not installed in its compile-time default
# location
2000-07-31 21:29:14 +02:00
#
# mysql.server works by first doing a cd to the base directory and from there
2001-06-28 09:49:16 +02:00
# executing mysqld_safe
2000-07-31 21:29:14 +02:00
2009-09-23 01:26:08 +02:00
# Initialize script globals
2003-06-14 11:29:42 +02:00
KILL_MYSQLD = 1;
2005-10-31 20:15:44 +01:00
MYSQLD =
2007-05-05 03:06:36 +02:00
niceness = 0
2009-09-23 01:26:08 +02:00
mysqld_ld_preload =
mysqld_ld_library_path =
2007-07-28 01:20:43 +02:00
# Initial logging status: error log is not open, and not using syslog
logging = init
want_syslog = 0
syslog_tag =
2009-03-16 20:28:06 +01:00
user = '@MYSQLD_USER@'
2007-05-05 03:06:36 +02:00
pid_file =
err_log =
2003-06-14 11:29:42 +02:00
2007-07-28 01:20:43 +02:00
syslog_tag_mysqld = mysqld
syslog_tag_mysqld_safe = mysqld_safe
2000-07-31 21:29:14 +02:00
trap '' 1 2 3 15 # we shouldn't let anyone kill us
2002-12-23 14:36:40 +01:00
umask 007
2000-07-31 21:29:14 +02:00
defaults =
case " $1 " in
2000-10-20 16:39:23 +02:00
--no-defaults| --defaults-file= *| --defaults-extra-file= *)
2000-07-31 21:29:14 +02:00
defaults = " $1 " ; shift
; ;
esac
2005-02-03 04:41:33 +01:00
usage ( ) {
cat <<EOF
Usage: $0 [ OPTIONS]
--no-defaults Don' t read the system defaults file
--defaults-file= FILE Use the specified defaults file
--defaults-extra-file= FILE Also use defaults from the specified file
--ledir= DIRECTORY Look for mysqld in the specified directory
--open-files-limit= LIMIT Limit the number of open files
--core-file-size= LIMIT Limit core files to the specified size
--timezone= TZ Set the system timezone
2009-09-23 01:26:08 +02:00
--malloc-lib= LIB Preload shared library LIB if available
2005-02-03 04:41:33 +01:00
--mysqld= FILE Use the specified file as mysqld
--mysqld-version= VERSION Use "mysqld-VERSION" as mysqld
--nice= NICE Set the scheduling priority of mysqld
2010-03-01 23:40:24 +01:00
--plugin-dir= DIR Plugins are under DIR or DIR/VERSION, if
VERSION is given
2005-02-03 04:41:33 +01:00
--skip-kill-mysqld Don' t try to kill stray mysqld processes
2007-05-05 03:06:36 +02:00
--syslog Log messages to syslog with 'logger'
2007-07-28 01:20:43 +02:00
--skip-syslog Log messages to error log ( default)
--syslog-tag= TAG Pass -t "mysqld-TAG" to 'logger'
2005-02-03 04:41:33 +01:00
All other options are passed to the mysqld program.
EOF
exit 1
}
2007-07-28 01:20:43 +02:00
my_which ( )
{
save_ifs = " ${ IFS -UNSET } "
IFS = :
2009-03-16 20:28:06 +01:00
ret = 0
2007-07-28 01:20:43 +02:00
for file
do
2009-05-25 18:21:40 +02:00
for dir in $PATH
2007-07-28 01:20:43 +02:00
do
if [ -f " $dir / $file " ]
then
echo " $dir / $file "
continue 2
fi
done
2009-03-16 20:28:06 +01:00
ret = 1 #signal an error
break
2007-07-28 01:20:43 +02:00
done
2009-03-16 20:28:06 +01:00
2007-07-28 01:20:43 +02:00
if [ " $save_ifs " = UNSET ]
then
unset IFS
else
IFS = " $save_ifs "
fi
2009-03-16 20:28:06 +01:00
return $ret # Success
2007-07-28 01:20:43 +02:00
}
2007-05-05 03:06:36 +02:00
log_generic ( ) {
priority = " $1 "
shift
msg = " `date +'%y%m%d %H:%M:%S'` mysqld_safe $* "
echo " $msg "
2007-07-28 01:20:43 +02:00
case $logging in
init) ; ; # Just echo the message, don't save it anywhere
file) echo " $msg " >> " $err_log " ; ;
syslog) logger -t " $syslog_tag_mysqld_safe " -p " $priority " " $* " ; ;
*)
echo "Internal program error (non-fatal):" \
" unknown logging method ' $logging ' " >& 2
; ;
esac
2007-05-05 03:06:36 +02:00
}
log_error ( ) {
log_generic daemon.error " $@ " >& 2
}
log_notice ( ) {
log_generic daemon.notice " $@ "
}
eval_log_error ( ) {
cmd = " $1 "
2007-07-28 01:20:43 +02:00
case $logging in
file) cmd = " $cmd >> " ` shell_quote_string " $err_log " ` " 2>&1" ; ;
syslog)
# mysqld often prefixes its messages with a timestamp, which is
# redundant when logging to syslog (which adds its own timestamp)
# However, we don't strip the timestamp with sed here, because
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
# which means that messages may not get sent to syslog until the
# mysqld process quits.
cmd = " $cmd 2>&1 | logger -t ' $syslog_tag_mysqld ' -p daemon.error "
; ;
*)
echo "Internal program error (non-fatal):" \
" unknown logging method ' $logging ' " >& 2
; ;
esac
2007-05-05 03:06:36 +02:00
#echo "Running mysqld: [$cmd]"
eval " $cmd "
}
2006-05-10 19:33:36 +02:00
shell_quote_string( ) {
# This sed command makes sure that any special chars are quoted,
# so the arg gets passed exactly to the server.
echo " $1 " | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
}
2005-02-03 04:41:33 +01:00
2000-07-31 21:29:14 +02:00
parse_arguments( ) {
2000-11-19 02:34:20 +01:00
# We only need to pass arguments through to the server if we don't
# handle them here. So, we collect unrecognized options (passed on
# the command line) into the args variable.
pick_args =
if test " $1 " = PICK-ARGS-FROM-ARGV
then
pick_args = 1
shift
fi
for arg do
2009-11-18 21:36:17 +01:00
# the parameter after "=", or the whole $arg if no match
val = ` echo " $arg " | sed -e 's;^--[^=]*=;;' `
# what's before "=", or the whole $arg if no match
optname = ` echo " $arg " | sed -e 's/^\(--[^=]*\)=.*$/\1/' `
# replace "_" by "-" ; mysqld_safe must accept "_" like mysqld does.
optname_subst = ` echo " $optname " | sed 's/_/-/g' `
arg = ` echo $arg | sed " s/^ $optname / $optname_subst / " `
2000-11-19 02:34:20 +01:00
case " $arg " in
# these get passed explicitly to mysqld
2007-05-05 03:06:36 +02:00
--basedir= *) MY_BASEDIR_VERSION = " $val " ; ;
--datadir= *) DATADIR = " $val " ; ;
--pid-file= *) pid_file = " $val " ; ;
2010-03-01 23:40:24 +01:00
--plugin-dir= *) PLUGIN_DIR = " $val " ; ;
2007-05-05 03:06:36 +02:00
--user= *) user = " $val " ; SET_USER = 1 ; ;
2000-11-19 02:34:20 +01:00
2006-05-10 19:33:36 +02:00
# these might have been set in a [mysqld_safe] section of my.cnf
2003-09-27 18:54:22 +02:00
# they are added to mysqld command line to override settings from my.cnf
2007-05-05 03:06:36 +02:00
--log-error= *) err_log = " $val " ; ;
--port= *) mysql_tcp_port = " $val " ; ;
--socket= *) mysql_unix_port = " $val " ; ;
2000-11-19 02:34:20 +01:00
2001-06-28 09:49:16 +02:00
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
2007-05-05 03:06:36 +02:00
--core-file-size= *) core_file_size = " $val " ; ;
--ledir= *) ledir = " $val " ; ;
2009-09-23 01:26:08 +02:00
--malloc-lib= *) set_malloc_lib " $val " ; ;
2007-05-05 03:06:36 +02:00
--mysqld= *) MYSQLD = " $val " ; ;
2001-04-13 21:09:33 +02:00
--mysqld-version= *)
2007-05-05 03:06:36 +02:00
if test -n " $val "
then
MYSQLD = " mysqld- $val "
2010-03-01 23:40:24 +01:00
PLUGIN_VARIANT = " / $val "
2007-05-05 03:06:36 +02:00
else
MYSQLD = "mysqld"
fi
2005-02-03 04:41:33 +01:00
; ;
2007-05-05 03:06:36 +02:00
--nice= *) niceness = " $val " ; ;
--open-files-limit= *) open_files = " $val " ; ;
2010-04-09 13:47:18 +02:00
--open_files_limit= *) open_files = " $val " ; ;
2007-05-05 03:06:36 +02:00
--skip-kill-mysqld*) KILL_MYSQLD = 0 ; ;
2007-07-28 01:20:43 +02:00
--syslog) want_syslog = 1 ; ;
--skip-syslog) want_syslog = 0 ; ;
--syslog-tag= *) syslog_tag = " $val " ; ;
2007-05-05 03:06:36 +02:00
--timezone= *) TZ = " $val " ; export TZ; ; ;
--help) usage ; ;
2000-11-19 02:34:20 +01:00
*)
if test -n " $pick_args "
then
2006-05-10 19:33:36 +02:00
append_arg_to_args " $arg "
2000-11-19 02:34:20 +01:00
fi
; ;
2000-07-31 21:29:14 +02:00
esac
done
}
2003-06-14 11:29:42 +02:00
2009-09-23 01:26:08 +02:00
# Add a single shared library to the list of libraries which will be added to
# LD_PRELOAD for mysqld
#
# Since LD_PRELOAD is a space-separated value (for historical reasons), if a
# shared lib's path contains spaces, that path will be prepended to
# LD_LIBRARY_PATH and stripped from the lib value.
add_mysqld_ld_preload( ) {
lib_to_add = " $1 "
log_notice " Adding ' $lib_to_add ' to LD_PRELOAD for mysqld "
case " $lib_to_add " in
*' ' *)
# Must strip path from lib, and add it to LD_LIBRARY_PATH
lib_file = ` basename " $lib_to_add " `
case " $lib_file " in
*' ' *)
# The lib file itself has a space in its name, and can't
# be used in LD_PRELOAD
log_error " library name ' $lib_to_add ' contains spaces and can not be used with LD_PRELOAD "
exit 1
; ;
esac
lib_path = ` dirname " $lib_to_add " `
lib_to_add = " $lib_file "
[ -n " $mysqld_ld_library_path " ] && mysqld_ld_library_path = " $mysqld_ld_library_path : "
mysqld_ld_library_path = " $mysqld_ld_library_path $lib_path "
; ;
esac
# LD_PRELOAD is a space-separated
[ -n " $mysqld_ld_preload " ] && mysqld_ld_preload = " $mysqld_ld_preload "
mysqld_ld_preload = " ${ mysqld_ld_preload } $lib_to_add "
}
# Returns LD_PRELOAD (and LD_LIBRARY_PATH, if needed) text, quoted to be
# suitable for use in the eval that calls mysqld.
#
# All values in mysqld_ld_preload are prepended to LD_PRELOAD.
mysqld_ld_preload_text( ) {
text =
if [ -n " $mysqld_ld_preload " ] ; then
new_text = " $mysqld_ld_preload "
[ -n " $LD_PRELOAD " ] && new_text = " $new_text $LD_PRELOAD "
text = " ${ text } LD_PRELOAD= " ` shell_quote_string " $new_text " ` ' '
fi
if [ -n " $mysqld_ld_library_path " ] ; then
new_text = " $mysqld_ld_library_path "
[ -n " $LD_LIBRARY_PATH " ] && new_text = " $new_text : $LD_LIBRARY_PATH "
text = " ${ text } LD_LIBRARY_PATH= " ` shell_quote_string " $new_text " ` ' '
fi
echo " $text "
}
mysql_config =
get_mysql_config( ) {
if [ -z " $mysql_config " ] ; then
mysql_config = ` echo " $0 " | sed 's,/[^/][^/]*$,/mysql_config,' `
if [ ! -x " $mysql_config " ] ; then
log_error " Can not run mysql_config $@ from ' $mysql_config ' "
exit 1
fi
fi
" $mysql_config " " $@ "
}
# set_malloc_lib LIB
# - If LIB is empty, do nothing and return
# - If LIB is 'tcmalloc', look for tcmalloc shared library in /usr/lib
# then pkglibdir. tcmalloc is part of the Google perftools project.
# - If LIB is an absolute path, assume it is a malloc shared library
#
# Put LIB in mysqld_ld_preload, which will be added to LD_PRELOAD when
# running mysqld. See ld.so for details.
set_malloc_lib( ) {
malloc_lib = " $1 "
if [ " $malloc_lib " = tcmalloc ] ; then
pkglibdir = ` get_mysql_config --variable= pkglibdir`
malloc_lib =
# This list is kept intentionally simple. Simply set --malloc-lib
# to a full path if another location is desired.
2010-05-12 13:51:23 +02:00
for libdir in /usr/lib " $pkglibdir " " $pkglibdir /mysql " ; do
2009-09-23 01:26:08 +02:00
for flavor in _minimal '' _and_profiler _debug; do
tmp = " $libdir /libtcmalloc $flavor .so "
#log_notice "DEBUG: Checking for malloc lib '$tmp'"
[ -r " $tmp " ] || continue
malloc_lib = " $tmp "
break 2
done
done
if [ -z " $malloc_lib " ] ; then
log_error " no shared library for --malloc-lib=tcmalloc found in /usr/lib or $pkglibdir "
exit 1
fi
fi
# Allow --malloc-lib='' to override other settings
[ -z " $malloc_lib " ] && return
case " $malloc_lib " in
/*)
if [ ! -r " $malloc_lib " ] ; then
log_error " --malloc-lib ' $malloc_lib ' can not be read and will not be used "
exit 1
fi
; ;
*)
log_error "--malloc-lib must be an absolute path or 'tcmalloc'; " \
" ignoring value ' $malloc_lib ' "
exit 1
; ;
esac
add_mysqld_ld_preload " $malloc_lib "
}
2005-06-25 02:14:16 +02:00
#
# First, try to find BASEDIR and ledir (where mysqld is)
2007-12-04 02:19:35 +01:00
#
if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null
then
relpkgdata = ` echo '@pkgdatadir@' | sed -e 's,^@prefix@,,' -e 's,^/,,' -e 's,^,./,' `
else
# pkgdatadir is not relative to prefix
relpkgdata = '@pkgdatadir@'
fi
2005-06-25 02:14:16 +02:00
2000-07-31 21:29:14 +02:00
MY_PWD = ` pwd `
2005-06-25 02:14:16 +02:00
# Check for the directories we would expect from a binary release install
2009-03-16 19:54:28 +01:00
if test -n " $MY_BASEDIR_VERSION " -a -d " $MY_BASEDIR_VERSION "
2000-07-31 21:29:14 +02:00
then
2009-03-16 19:54:28 +01:00
# BASEDIR is already overridden on command line. Do not re-set.
# Use BASEDIR to discover le.
if test -x " $MY_BASEDIR_VERSION /libexec/mysqld "
then
ledir = " $MY_BASEDIR_VERSION /libexec "
2010-01-24 16:23:16 +01:00
elif test -x " $MY_BASEDIR_VERSION /sbin/mysqld "
then
ledir = " $MY_BASEDIR_VERSION /sbin "
2009-03-16 19:54:28 +01:00
else
ledir = " $MY_BASEDIR_VERSION /bin "
fi
elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /bin/mysqld "
then
MY_BASEDIR_VERSION = " $MY_PWD " # Where bin, share and data are
ledir = " $MY_PWD /bin " # Where mysqld is
2005-06-25 02:14:16 +02:00
# Check for the directories we would expect from a source install
2009-03-16 19:54:28 +01:00
elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /libexec/mysqld "
2000-07-31 21:29:14 +02:00
then
2009-03-16 19:54:28 +01:00
MY_BASEDIR_VERSION = " $MY_PWD " # Where libexec, share and var are
ledir = " $MY_PWD /libexec " # Where mysqld is
2010-01-24 16:23:16 +01:00
elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /sbin/mysqld "
then
MY_BASEDIR_VERSION = " $MY_PWD " # Where sbin, share and var are
ledir = " $MY_PWD /sbin " # Where mysqld is
2005-06-25 02:14:16 +02:00
# Since we didn't find anything, used the compiled-in defaults
2000-07-31 21:29:14 +02:00
else
2009-03-16 20:28:06 +01:00
MY_BASEDIR_VERSION = '@prefix@'
ledir = '@libexecdir@'
2000-07-31 21:29:14 +02:00
fi
2007-12-04 02:19:35 +01:00
2005-06-25 02:14:16 +02:00
#
# Second, try to find the data directory
#
# Try where the binary installs put it
if test -d $MY_BASEDIR_VERSION /data/mysql
then
2000-07-31 21:29:14 +02:00
DATADIR = $MY_BASEDIR_VERSION /data
2005-05-27 02:44:06 +02:00
if test -z " $defaults " -a -r " $DATADIR /my.cnf "
2001-02-17 18:04:33 +01:00
then
2005-01-04 19:13:47 +01:00
defaults = " --defaults-extra-file= $DATADIR /my.cnf "
2001-02-17 18:04:33 +01:00
fi
2005-06-25 02:14:16 +02:00
# Next try where the source installs put it
elif test -d $MY_BASEDIR_VERSION /var/mysql
2000-07-31 21:29:14 +02:00
then
DATADIR = $MY_BASEDIR_VERSION /var
2005-06-25 02:14:16 +02:00
# Or just give up and use our compiled-in default
2000-07-31 21:29:14 +02:00
else
DATADIR = @localstatedir@
fi
2005-02-23 17:59:54 +01:00
2005-01-04 19:13:47 +01:00
if test -z " $MYSQL_HOME "
then
2005-02-23 17:59:54 +01:00
if test -r " $MY_BASEDIR_VERSION /my.cnf " && test -r " $DATADIR /my.cnf "
then
2007-05-05 03:06:36 +02:00
log_error " WARNING: Found two instances of my.cnf -
$MY_BASEDIR_VERSION /my.cnf and
$DATADIR /my.cnf
IGNORING $DATADIR /my.cnf"
2005-02-23 17:59:54 +01:00
MYSQL_HOME = $MY_BASEDIR_VERSION
elif test -r " $DATADIR /my.cnf "
then
2007-05-05 03:06:36 +02:00
log_error " WARNING: Found $DATADIR /my.cnf
The data directory is a deprecated location for my.cnf, please move it to
$MY_BASEDIR_VERSION /my.cnf"
2005-02-23 17:59:54 +01:00
MYSQL_HOME = $DATADIR
else
MYSQL_HOME = $MY_BASEDIR_VERSION
fi
2005-01-04 19:13:47 +01:00
fi
export MYSQL_HOME
2000-07-31 21:29:14 +02:00
2000-11-19 02:34:20 +01:00
2001-06-28 09:49:16 +02:00
# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
2000-07-31 21:29:14 +02:00
# and then merge with the command line arguments
2009-03-16 19:54:28 +01:00
if test -x " $MY_BASEDIR_VERSION /bin/my_print_defaults "
then
print_defaults = " $MY_BASEDIR_VERSION /bin/my_print_defaults "
elif test -x ./bin/my_print_defaults
2000-11-19 02:34:20 +01:00
then
2000-07-31 21:29:14 +02:00
print_defaults = "./bin/my_print_defaults"
2000-11-19 02:34:20 +01:00
elif test -x @bindir@/my_print_defaults
then
2000-07-31 21:29:14 +02:00
print_defaults = "@bindir@/my_print_defaults"
2000-11-19 02:34:20 +01:00
elif test -x @bindir@/mysql_print_defaults
then
2000-07-31 21:29:14 +02:00
print_defaults = "@bindir@/mysql_print_defaults"
else
print_defaults = "my_print_defaults"
fi
2000-11-19 02:34:20 +01:00
2006-05-10 19:33:36 +02:00
append_arg_to_args ( ) {
args = " $args " ` shell_quote_string " $1 " `
}
2000-11-19 02:34:20 +01:00
args =
2007-05-05 03:06:36 +02:00
2003-12-19 23:08:20 +01:00
SET_USER = 2
2004-11-30 22:17:43 +01:00
parse_arguments ` $print_defaults $defaults --loose-verbose mysqld server`
2003-12-19 23:08:20 +01:00
if test $SET_USER -eq 2
then
SET_USER = 0
fi
2007-05-05 03:06:36 +02:00
2004-11-30 22:17:43 +01:00
parse_arguments ` $print_defaults $defaults --loose-verbose mysqld_safe safe_mysqld`
2000-11-19 02:34:20 +01:00
parse_arguments PICK-ARGS-FROM-ARGV " $@ "
2000-07-31 21:29:14 +02:00
2007-05-05 03:06:36 +02:00
# Determine what logging facility to use
2007-07-28 01:20:43 +02:00
# Ensure that 'logger' exists, if it's requested
if [ $want_syslog -eq 1 ]
then
my_which logger > /dev/null 2>& 1
if [ $? -ne 0 ]
then
2007-07-30 21:35:36 +02:00
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe."
exit 1
2007-07-28 01:20:43 +02:00
fi
fi
if [ -n " $err_log " -o $want_syslog -eq 0 ]
2007-05-05 03:06:36 +02:00
then
if [ -n " $err_log " ]
then
2007-07-09 23:30:19 +02:00
# mysqld adds ".err" if there is no extension on the --log-error
2007-05-05 03:06:36 +02:00
# argument; must match that here, or mysqld_safe will write to a
# different log file than mysqld
# mysqld does not add ".err" to "--log-error=foo."; it considers a
# trailing "." as an extension
if expr " $err_log " : '.*\.[^/]*$' > /dev/null
then
:
else
err_log = " $err_log " .err
fi
case " $err_log " in
/* ) ; ;
* ) err_log = " $DATADIR / $err_log " ; ;
esac
else
err_log = $DATADIR /` @HOSTNAME@` .err
fi
append_arg_to_args " --log-error= $err_log "
2007-07-28 01:20:43 +02:00
if [ $want_syslog -eq 1 ]
2007-05-05 03:06:36 +02:00
then
# User explicitly asked for syslog, so warn that it isn't used
2007-07-28 01:20:43 +02:00
log_error "Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect."
2007-05-05 03:06:36 +02:00
fi
2007-07-28 01:20:43 +02:00
# Log to err_log file
log_notice " Logging to ' $err_log '. "
logging = file
else
if [ -n " $syslog_tag " ]
then
# Sanitize the syslog tag
syslog_tag = ` echo " $syslog_tag " | sed -e 's/[^a-zA-Z0-9_-]/_/g' `
syslog_tag_mysqld_safe = " ${ syslog_tag_mysqld_safe } - $syslog_tag "
syslog_tag_mysqld = " ${ syslog_tag_mysqld } - $syslog_tag "
fi
log_notice "Logging to syslog."
logging = syslog
2007-05-05 03:06:36 +02:00
fi
2007-07-10 00:10:43 +02:00
USER_OPTION = ""
if test -w / -o " $USER " = "root"
then
if test " $user " != "root" -o $SET_USER = 1
then
USER_OPTION = " --user= $user "
fi
# Change the err log to the right user, if it is in use
2007-08-24 16:40:26 +02:00
if [ $want_syslog -eq 0 ] ; then
2009-05-08 02:25:23 +02:00
touch " $err_log "
chown $user " $err_log "
2007-07-10 00:10:43 +02:00
fi
if test -n " $open_files "
then
ulimit -n $open_files
fi
fi
2010-04-09 13:47:18 +02:00
if test -n " $open_files "
then
append_arg_to_args " --open-files-limit= $open_files "
fi
2007-05-05 03:06:36 +02:00
safe_mysql_unix_port = ${ mysql_unix_port :- ${ MYSQL_UNIX_PORT :- @MYSQL_UNIX_ADDR@ } }
2005-03-02 21:19:44 +01:00
# Make sure that directory for $safe_mysql_unix_port exists
mysql_unix_port_dir = ` dirname $safe_mysql_unix_port `
if [ ! -d $mysql_unix_port_dir ]
then
mkdir $mysql_unix_port_dir
chown $user $mysql_unix_port_dir
2006-12-14 21:18:36 +01:00
chmod 755 $mysql_unix_port_dir
2005-03-02 21:19:44 +01:00
fi
2006-03-02 22:53:38 +01:00
# If the user doesn't specify a binary, we assume name "mysqld"
2005-10-31 20:15:44 +01:00
if test -z " $MYSQLD "
then
2006-03-02 22:53:38 +01:00
MYSQLD = mysqld
2005-10-31 20:15:44 +01:00
fi
2005-03-02 21:19:44 +01:00
2009-03-16 20:28:06 +01:00
if test ! -x " $ledir / $MYSQLD "
2000-07-31 21:29:14 +02:00
then
2007-05-05 03:06:36 +02:00
log_error " The file $ledir / $MYSQLD
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
2007-10-08 18:40:21 +02:00
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
2000-11-19 02:34:20 +01:00
exit 1
2000-07-31 21:29:14 +02:00
fi
2000-11-29 21:21:48 +01:00
if test -z " $pid_file "
then
2009-03-16 20:28:06 +01:00
pid_file = " $DATADIR /`@HOSTNAME@`.pid "
2000-11-29 21:21:48 +01:00
else
case " $pid_file " in
/* ) ; ;
* ) pid_file = " $DATADIR / $pid_file " ; ;
esac
fi
2006-05-10 19:33:36 +02:00
append_arg_to_args " --pid-file= $pid_file "
2003-09-27 18:54:22 +02:00
if test -n " $mysql_unix_port "
then
2006-05-10 19:33:36 +02:00
append_arg_to_args " --socket= $mysql_unix_port "
2003-09-27 18:54:22 +02:00
fi
if test -n " $mysql_tcp_port "
then
2006-05-10 19:33:36 +02:00
append_arg_to_args " --port= $mysql_tcp_port "
2003-09-27 18:54:22 +02:00
fi
2000-07-31 21:29:14 +02:00
2003-06-12 13:52:24 +02:00
if test $niceness -eq 0
then
NOHUP_NICENESS = "nohup"
else
NOHUP_NICENESS = " nohup nice - $niceness "
fi
2001-10-22 17:22:55 +02:00
# Using nice with no args to get the niceness level is GNU-specific.
# This check could be extended for other operating systems (e.g.,
# BSD could use "nohup sh -c 'ps -o nice -p $$' | tail -1").
# But, it also seems that GNU nohup is the only one which messes
# with the priority, so this is okay.
if nohup nice > /dev/null 2>& 1
2000-09-13 00:08:34 +02:00
then
2001-10-22 17:22:55 +02:00
normal_niceness = ` nice`
2007-05-05 03:06:36 +02:00
nohup_niceness = ` nohup nice 2>/dev/null`
2001-10-22 17:22:55 +02:00
numeric_nice_values = 1
for val in $normal_niceness $nohup_niceness
do
case " $val " in
-[ 0-9] | -[ 0-9] [ 0-9] | -[ 0-9] [ 0-9] [ 0-9] | \
[ 0-9] | [ 0-9] [ 0-9] | [ 0-9] [ 0-9] [ 0-9] )
; ;
* )
numeric_nice_values = 0 ; ;
esac
done
if test $numeric_nice_values -eq 1
then
nice_value_diff = ` expr $nohup_niceness - $normal_niceness `
if test $? -eq 0 && test $nice_value_diff -gt 0 && \
nice --$nice_value_diff echo testing > /dev/null 2>& 1
then
# nohup increases the priority (bad), and we are permitted
2003-06-12 13:52:24 +02:00
# to lower the priority with respect to the value the user
# might have been given
niceness = ` expr $niceness - $nice_value_diff `
NOHUP_NICENESS = " nice - $niceness nohup "
2001-10-22 17:22:55 +02:00
fi
fi
else
if nohup echo testing > /dev/null 2>& 1
then
:
else
# nohup doesn't work on this system
NOHUP_NICENESS = ""
fi
2000-07-31 21:29:14 +02:00
fi
2006-04-18 04:57:50 +02:00
# Try to set the core file size (even if we aren't root) because many systems
# don't specify a hard limit on core file size.
if test -n " $core_file_size "
then
ulimit -c $core_file_size
2000-09-13 00:08:34 +02:00
fi
2000-07-31 21:29:14 +02:00
#
# If there exists an old pid file, check if the daemon is already running
# Note: The switches to 'ps' may depend on your operating system
2009-05-08 02:25:23 +02:00
if test -f " $pid_file "
2000-07-31 21:29:14 +02:00
then
2009-05-08 02:25:23 +02:00
PID = ` cat " $pid_file " `
2000-07-31 21:29:14 +02:00
if @CHECK_PID@
then
if @FIND_PROC@
then # The pid contains a mysqld process
2007-05-05 03:06:36 +02:00
log_error "A mysqld process already exists"
2000-11-19 02:34:20 +01:00
exit 1
2000-07-31 21:29:14 +02:00
fi
fi
2009-05-08 02:25:23 +02:00
rm -f " $pid_file "
if test -f " $pid_file "
2000-07-31 21:29:14 +02:00
then
2007-05-05 03:06:36 +02:00
log_error " Fatal error: Can't remove the pid file:
$pid_file
Please remove it manually and start $0 again;
mysqld daemon not started"
2000-11-19 02:34:20 +01:00
exit 1
2000-07-31 21:29:14 +02:00
fi
fi
#
2003-07-15 12:50:17 +02:00
# Uncomment the following lines if you want all tables to be automatically
# checked and repaired during startup. You should add sensible key_buffer
# and sort_buffer values to my.cnf to improve check performance or require
# less disk space.
# Alternatively, you can start mysqld with the "myisam-recover" option. See
# the manual for details.
2000-07-31 21:29:14 +02:00
#
# echo "Checking tables in $DATADIR"
2003-07-15 12:50:17 +02:00
# $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check $DATADIR/*/*.MYI
# $MY_BASEDIR_VERSION/bin/isamchk --silent --force $DATADIR/*/*.ISM
2000-07-31 21:29:14 +02:00
# Does this work on all systems?
#if type ulimit | grep "shell builtin" > /dev/null
#then
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
#fi
2009-09-23 01:26:08 +02:00
cmd = " `mysqld_ld_preload_text` $NOHUP_NICENESS "
2007-05-05 03:06:36 +02:00
2010-06-30 13:19:54 +02:00
plugin_dir = " ${ PLUGIN_DIR :- ` get_mysql_config --variable= plugindir` } ${ PLUGIN_VARIANT } "
2010-03-01 23:40:24 +01:00
2007-05-05 03:06:36 +02:00
for i in " $ledir / $MYSQLD " " $defaults " " --basedir= $MY_BASEDIR_VERSION " \
2010-03-01 23:40:24 +01:00
" --datadir= $DATADIR " " --plugin-dir= $plugin_dir " " $USER_OPTION "
2007-05-05 03:06:36 +02:00
do
cmd = " $cmd " ` shell_quote_string " $i " `
done
cmd = " $cmd $args "
# Avoid 'nohup: ignoring input' warning
test -n " $NOHUP_NICENESS " && cmd = " $cmd < /dev/null "
log_notice " Starting $MYSQLD daemon with databases from $DATADIR "
2000-07-31 21:29:14 +02:00
while true
do
2009-05-08 02:25:23 +02:00
rm -f $safe_mysql_unix_port " $pid_file " # Some extra safety
2006-05-10 19:33:36 +02:00
2007-05-05 03:06:36 +02:00
eval_log_error " $cmd "
2006-05-10 19:33:36 +02:00
2009-05-08 02:25:23 +02:00
if test ! -f " $pid_file " # This is removed if normal shutdown
2000-07-31 21:29:14 +02:00
then
2000-11-19 02:34:20 +01:00
break
2000-07-31 21:29:14 +02:00
fi
2000-11-19 02:34:20 +01:00
2005-04-20 20:10:28 +02:00
if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
2000-07-31 21:29:14 +02:00
then
# Test if one process was hanging.
# This is only a fix for Linux (running as base 3 mysqld processes)
# but should work for the rest of the servers.
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
# kill -9 is used or the process won't react on the kill.
2005-01-04 01:49:29 +01:00
numofproces = ` ps xaww | grep -v "grep" | grep " $ledir / $MYSQLD \> " | grep -c " pid-file= $pid_file " `
2004-09-01 03:59:41 +02:00
2007-05-05 03:06:36 +02:00
log_notice " Number of processes running now: $numofproces "
2000-07-31 21:29:14 +02:00
I = 1
while test " $I " -le " $numofproces "
do
2005-01-04 01:49:29 +01:00
PROC = ` ps xaww | grep " $ledir / $MYSQLD \> " | grep -v "grep" | grep " pid-file= $pid_file " | sed -n '$p' `
2004-09-07 13:48:38 +02:00
for T in $PROC
do
break
done
# echo "TEST $I - $T **"
if kill -9 $T
2004-09-01 03:59:41 +02:00
then
2007-05-05 03:06:36 +02:00
log_error " $MYSQLD process hanging, pid $T - killed "
else
2004-09-07 13:48:38 +02:00
break
2004-09-01 03:59:41 +02:00
fi
2004-09-07 13:48:38 +02:00
I = ` expr $I + 1`
2000-07-31 21:29:14 +02:00
done
fi
2007-05-05 03:06:36 +02:00
log_notice "mysqld restarted"
2000-07-31 21:29:14 +02:00
done
2007-05-05 03:06:36 +02:00
log_notice " mysqld from pid file $pid_file ended "
2004-09-07 13:48:38 +02:00