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