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