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