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