|
|
2aefdf |
#!/bin/sh
|
|
|
2aefdf |
|
|
|
2aefdf |
# Some useful functions used in other MySQL helper scripts
|
|
|
2aefdf |
# This scripts defines variables datadir, errlogfile, socketfile
|
|
|
2aefdf |
|
|
|
2aefdf |
export LC_ALL=C
|
|
|
2aefdf |
|
|
|
2aefdf |
# extract value of a MySQL option from config files
|
|
|
2aefdf |
# Usage: get_mysql_option VARNAME DEFAULT SECTION [ SECTION, ... ]
|
|
|
2aefdf |
# result is returned in $result
|
|
|
2aefdf |
# We use my_print_defaults which prints all options from multiple files,
|
|
|
2aefdf |
# with the more specific ones later; hence take the last match.
|
|
|
2aefdf |
get_mysql_option(){
|
|
|
2aefdf |
if [ $# -ne 3 ] ; then
|
|
|
2aefdf |
echo "get_mysql_option requires 3 arguments: section option default_value"
|
|
|
2aefdf |
return
|
|
|
2aefdf |
fi
|
|
|
2aefdf |
sections="$1"
|
|
|
2aefdf |
option_name="$2"
|
|
|
2aefdf |
default_value="$3"
|
|
|
2aefdf |
result=`@bindir@/my_print_defaults $my_print_defaults_extra_args $sections | sed -n "s/^--${option_name}=//p" | tail -n 1`
|
|
|
2aefdf |
if [ -z "$result" ]; then
|
|
|
2aefdf |
# not found, use default
|
|
|
2aefdf |
result="${default_value}"
|
|
|
2aefdf |
fi
|
|
|
2aefdf |
}
|
|
|
2aefdf |
|
|
|
2aefdf |
# For the case of running more instances via systemd, scrits that source
|
|
|
2aefdf |
# this file can get --default-group-suffix or similar option as the first
|
|
|
2aefdf |
# argument. The utility my_print_defaults needs to use it as well, so the
|
|
|
2aefdf |
# scripts sourcing this file work with the same options as the daemon.
|
|
|
2aefdf |
my_print_defaults_extra_args=''
|
|
|
2aefdf |
while echo "$1" | grep -q '^--defaults' ; do
|
|
|
2aefdf |
my_print_defaults_extra_args="${my_print_defaults_extra_args} $1"
|
|
|
2aefdf |
shift
|
|
|
2aefdf |
done
|
|
|
2aefdf |
|
|
|
2aefdf |
# Defaults here had better match what mysqld_safe will default to
|
|
|
2aefdf |
# The option values are generally defined on three important places
|
|
|
2aefdf |
# on the default installation:
|
|
|
2aefdf |
# 1) default values are hardcoded in the code of mysqld daemon or
|
|
|
2aefdf |
# mysqld_safe script
|
|
|
2aefdf |
# 2) configurable values are defined in @sysconfdir@/my.cnf
|
|
|
2aefdf |
# 3) default values for helper scripts are specified bellow
|
|
|
2aefdf |
# So, in case values are defined in my.cnf, we need to get that value.
|
|
|
2aefdf |
# In case they are not defined in my.cnf, we need to get the same value
|
|
|
2aefdf |
# in the daemon, as in the helper scripts. Thus, default values here
|
|
|
2aefdf |
# must correspond with values defined in mysqld_safe script and source
|
|
|
2aefdf |
# code itself.
|
|
|
2aefdf |
|
|
|
2aefdf |
server_sections="mysqld_safe mysqld server mysqld-@MAJOR_VERSION@.@MINOR_VERSION@ client-server"
|
|
|
2aefdf |
|
|
|
2aefdf |
get_mysql_option "$server_sections" datadir "@MYSQL_DATADIR@"
|
|
|
2aefdf |
datadir="$result"
|
|
|
2aefdf |
|
|
|
2aefdf |
# if there is log_error in the my.cnf, my_print_defaults still
|
|
|
2aefdf |
# returns log-error
|
|
|
2aefdf |
# log-error might be defined in mysqld_safe and mysqld sections,
|
|
|
2aefdf |
# the former has bigger priority
|
|
|
2aefdf |
get_mysql_option "$server_sections" log-error "$datadir/`hostname`.err"
|
|
|
2aefdf |
errlogfile="$result"
|
|
|
2aefdf |
|
|
|
2aefdf |
get_mysql_option "$server_sections" socket "@MYSQL_UNIX_ADDR@"
|
|
|
2aefdf |
socketfile="$result"
|
|
|
2aefdf |
|
|
|
2aefdf |
get_mysql_option "$server_sections" pid-file "$datadir/`hostname`.pid"
|
|
|
2aefdf |
pidfile="$result"
|
|
|
2aefdf |
|