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