Blame SOURCES/mysql-scripts-common.sh

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