Blame SOURCES/mysql-scripts-common.sh

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