Blame SOURCES/mysql-scripts-common.sh

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