Blame SOURCES/mysql-scripts-common.sh

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