Blame SOURCES/mysql-scripts-common.sh

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