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