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