Blame SOURCES/mysql-scripts-common.sh

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