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