Blame SOURCES/mysql-scripts-common.sh

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