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