Blame SOURCES/mysql-scripts-common.sh

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