Blame SOURCES/mysql-scripts-common.sh

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