Blame SOURCES/mysql-scripts-common.sh

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