From f035de94cb635f94d93afef5c84414bfe3332160 Mon Sep 17 00:00:00 2001 From: Francesco Riosa Date: Tue, 31 Jan 2006 00:59:05 +0000 Subject: - pointer to http://www.gentoo.org/doc/en/mysql-upgrade-slotted.xml added - workarounds for test baselayout, also again starting also slotted MySQL > from only one file /etc/init.d/mysql Package-Manager: portage-2.1_pre3-r1 --- dev-db/mysql/ChangeLog | 9 +- dev-db/mysql/Manifest | 13 +- dev-db/mysql/files/mysql-slot.conf.d-r1 | 27 ++- dev-db/mysql/files/mysql-slot.conf.d-r2 | 87 --------- dev-db/mysql/files/mysql-slot.rc6-r2 | 263 ------------------------- dev-db/mysql/files/mysql-slot.rc6-r3 | 336 ++++++++++++++++++++++++++++++++ 6 files changed, 370 insertions(+), 365 deletions(-) delete mode 100644 dev-db/mysql/files/mysql-slot.conf.d-r2 delete mode 100755 dev-db/mysql/files/mysql-slot.rc6-r2 create mode 100644 dev-db/mysql/files/mysql-slot.rc6-r3 (limited to 'dev-db/mysql') diff --git a/dev-db/mysql/ChangeLog b/dev-db/mysql/ChangeLog index 0d9a7e1d4abc..b6c91629e007 100644 --- a/dev-db/mysql/ChangeLog +++ b/dev-db/mysql/ChangeLog @@ -1,6 +1,13 @@ # ChangeLog for dev-db/mysql # Copyright 2002-2006 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/ChangeLog,v 1.294 2006/01/24 19:25:57 vivo Exp $ +# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/ChangeLog,v 1.295 2006/01/31 00:59:05 vivo Exp $ + + 31 Jan 2006; Francesco Riosa files/mysql-slot.conf.d-r1, + -files/mysql-slot.conf.d-r2, -files/mysql-slot.rc6-r2, + +files/mysql-slot.rc6-r3: + - pointer to http://www.gentoo.org/doc/en/mysql-upgrade-slotted.xml added + - workarounds for test baselayout, also again starting also slotted MySQL + > from only one file /etc/init.d/mysql 24 Jan 2006; Francesco Riosa +files/my.cnf-4.1-r1, +files/logrotate-slot.mysql, files/mysql-slot.rc6-r2, diff --git a/dev-db/mysql/Manifest b/dev-db/mysql/Manifest index 4417707e9503..64ae85cfd974 100644 --- a/dev-db/mysql/Manifest +++ b/dev-db/mysql/Manifest @@ -1,7 +1,7 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -MD5 84ebd6a4f165a427c434e430088dde23 ChangeLog 59702 +MD5 2f23d9450b8f8f616678fecfd113de8a ChangeLog 60058 MD5 c6fcd70c34bed04e59808ec71c5bedfb files/digest-mysql-3.23.58-r1 140 MD5 0feb3b501c47708ea13707c8e4cdde9c files/digest-mysql-4.0.25-r2 139 MD5 201c8b31cd9eb58eec712e37d6f0c328 files/digest-mysql-4.0.26 139 @@ -23,11 +23,10 @@ MD5 625b4007f035e3da9a4f1eeee1db6b9c files/mysql-4.0.15.rc6 1187 MD5 d0fbdf4e41f2b52210eef6cb3a53e128 files/mysql-4.0.24-r1.rc6 1662 MD5 356c1b4211a0b3d229bcb09c7c8742a7 files/mysql-4.0.24-r2.rc6 2151 MD5 c8a9f17eb53cb46bd7ec6b3105cd8d23 files/mysql-slot.conf.d 3218 -MD5 624541a36c1aae85e3999078d2468215 files/mysql-slot.conf.d-r1 2999 -MD5 7855af91fd7c2253e5da6b6a0e245375 files/mysql-slot.conf.d-r2 3817 +MD5 9e2fe99528ea29fb4b4da6b7c564c90c files/mysql-slot.conf.d-r1 3693 MD5 2e915001528cb4b44591d907168b6a51 files/mysql-slot.rc6 8691 MD5 8158f25fbd80fba48f0d01b0889ea0b3 files/mysql-slot.rc6-r1 9016 -MD5 e498f5d3b097ab0ab2db0e46b2a8e9a0 files/mysql-slot.rc6-r2 7883 +MD5 c3f14442c46fb9f2941aa9ff37b9b199 files/mysql-slot.rc6-r3 10061 MD5 73be6460f548f6f73c70246a4cfd13a0 files/mysql.init 886 MD5 9ff84042930f67b14f418a9dcf78d860 files/mysqlmanager-slot.conf.d 1021 MD5 69488d8c4aca1adf37e4c24b39305487 files/mysqlmanager-slot.rc6 6614 @@ -45,7 +44,7 @@ MD5 51a06a62df32804d95eb0865d5117f07 mysql-5.1.4_alpha-r30.ebuild 1980 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) -iD8DBQFD1n9fKolR564NvWYRAvJLAKCL29ZHRrEqLQecCU3RcNoFMaVcrACfXK8a -KLovDnpK/aHzmeh43IFJmFE= -=u3z+ +iD8DBQFD3rZqKolR564NvWYRAl8LAKCKtUC1hH+Gne8W3mllc+AAhDT6hgCgw57l +AMJElS9ZNOsipkkk2VCxIFU= +=yx5B -----END PGP SIGNATURE----- diff --git a/dev-db/mysql/files/mysql-slot.conf.d-r1 b/dev-db/mysql/files/mysql-slot.conf.d-r1 index fae38f271506..faac4ad9031d 100644 --- a/dev-db/mysql/files/mysql-slot.conf.d-r1 +++ b/dev-db/mysql/files/mysql-slot.conf.d-r1 @@ -16,8 +16,8 @@ # mycnf : string [full path to my.cnf] # : specify the path to my.cnf file to be used # ----------------+----------------------------------------------------------- -# startup_timeout : integer [seconds] default 5 -# : time to wait for mysqld up and running, after this it's +# startup_timeout : integer [seconds] default 15 +# : time to wait for mysqld up and running, after this it's # : marked as failed # ----------------+----------------------------------------------------------- # @@ -44,21 +44,34 @@ # Be more verbose accept values from 1 to 4 #DEBUG=4 # -# The default location for the "master" pid file -#MYSQL_GLOB_PID_FILE="/var/run/svc-started-mysqld" +# The default location for the "master" pid file +# MYSQL_GLOB_PID_FILE="/var/run/svc-started-mysqld" # # The timeout for a failed attempt to stop a server # STOPTIMEOUT=120 # -## Examples: +## The parameters are passed in a bash array variable, +# the variable name is mysql_slot_[server-ver]_[server-num] +# Where "server-ver" and "server-num" are optional. +# in case are defined "server-num" MUST be of three digits. +# The first digit is the mayor version, the following two the minor +# i.e. having installed mysql-5.1.x "server-num" will be "501" +# "server-num" it's an optional number used mainly to start more servers +# of the same version. +# +# The /etc/init.d/mysql-* script will choose the parameters analyzing it's own name +# i.e. /etc/init.d/mysql-501 will look for mysql_slot_501 +# side note the script could be called "mysql-501_1" or "mysql.501.1" with the same result +# +# Examples: # # start a default server with default options: #mysql_slot_0=() # # start MySQL 7.5.x reniced, overriding some start parameters #mysql_slot_705=( -# "nice=-5" +# "nice=-5" # "server-id=123" # "log-bin="myhost" # "port=3307" @@ -66,7 +79,7 @@ # # start another server, same version, different my.cnf #mysql_slot_705_1=( -# "mycnf=/home/test/my.cnf" +# "mycnf=/home/test/my.cnf" # "server-id=124" #) # diff --git a/dev-db/mysql/files/mysql-slot.conf.d-r2 b/dev-db/mysql/files/mysql-slot.conf.d-r2 deleted file mode 100644 index 62c1320d59f8..000000000000 --- a/dev-db/mysql/files/mysql-slot.conf.d-r2 +++ /dev/null @@ -1,87 +0,0 @@ -# here is where to define which server start. -#> Additional parameters to be passed to mysqld at startup may be added here, -#> these one will override the ones in "my.cnf". -# -# Each /etc/init.d/mysql-* script read it's own here, see at the end for -#> a deeper explanation -# -# Below are described some suggested parameters to use -# The parameters not recognized will be passed through to the mysqld daemon -# To avoid starting a server just comment it's definition -# Last but not least, spaces are NOT allowed inside the parameters -# -# Parameter : description -# ----------------+----------------------------------------------------------- -# nice : integer [-20 .. 19 ] default 0 -# : change the priority of the server -20 (high) to 19 (low) -# : see "man nice 1" for description -# ----------------+----------------------------------------------------------- -# mycnf : string [full path to my.cnf] -# : specify the path to my.cnf file to be used -# ----------------+----------------------------------------------------------- -# startup_timeout : integer [seconds] default 15 -# : time to wait for mysqld up and running, after this it's -# : marked as failed -# ----------------+----------------------------------------------------------- -# stop_timeout : integer [seconds] default 120 -# : time to wait for a clean mysql shutdown -# ----------------+----------------------------------------------------------- -# -# Additional parameters -# Parameter : description -# ----------------+----------------------------------------------------------- -# server-id : integer [1 .. 255] -# : Uniquely identifies the server instance in the community -# : of replication partners. -# ----------------+----------------------------------------------------------- -# port : integer [1025 .. 65535] default 3306 -# : Port number to use for connection. -# : loose any meaning if skip-networking is set. -# ----------------+----------------------------------------------------------- -# skip-networking : NULL, Don't allow connection with TCP/IP. -# log-bin : string [name of the binlog files] -# : Log update queries in binary format. Optional (but -# : strongly recommended to avoid replication problems if -# : server's hostname changes) argument should be the chosen -# : location for the binary log files. -# ----------------+----------------------------------------------------------- -# Additionally the following variables are recognized: -# -# Be more verbose accept values from 1 to 4 -#DEBUG=4 -# - -## The parameters are passed in a bash array variable, -# the variable name is mysql_slot_[server-ver]_[server-num] -# Where "server-ver" and "server-num" are optional. -# in case are defined "server-num" MUST be of three digits. -# The first digit is the mayor version, the following two the minor -# i.e. having installed mysql-5.1.x "server-num" will be "501" -# "server-num" it's an optional number used mainly to start more servers -# of the same version. -# -# The /etc/init.d/mysql-* script will choose the parameters analyzing it's own name -# i.e. /etc/init.d/mysql-501 will look for mysql_slot_501 -# side note the script could be called "mysql-501_1" or "mysql.501.1" with the same result -# -# Examples: -# -# start a default server with default options: -#mysql_slot=( ) -# or -#mysql_slot_0=( ) -# -# start MySQL 7.5.x reniced, overriding some start parameters -#mysql_slot_705=( -# "nice=-5" -# "server-id=123" -# "log-bin="myhost" -# "port=3307" -#) -# -# start another server, same version, different my.cnf -#mysql_slot_705_1=( -# "mycnf=/home/test/my.cnf" -# "server-id=124" -#) -# diff --git a/dev-db/mysql/files/mysql-slot.rc6-r2 b/dev-db/mysql/files/mysql-slot.rc6-r2 deleted file mode 100755 index c54d0906e9a0..000000000000 --- a/dev-db/mysql/files/mysql-slot.rc6-r2 +++ /dev/null @@ -1,263 +0,0 @@ -#!/sbin/runscript -# Copyright 1999-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/files/mysql-slot.rc6-r2,v 1.4 2006/01/24 19:25:57 vivo Exp $ - -# external binaryes used: which, sed, tac - -depend() { - use dns net localmount netmount nfsmount -} - -function wdebug() { - if [[ "${DEBUG}" -ge "${1}" ]] ; then - shift - echo "dbg: ${@}" - fi -} - -do_escape() { - # Ihatethisreallyverymuch - #echo "$1" | sed -e "s|'| |" -e "s|=|='|" -e "s|$|'|" - echo "$1" -} - -# int get_slot_config() -get_slot_config() { - - wdebug 4 ">>> get_slot_config()" - - # servers options are (also) defined in /etc/conf.d/mysql - [[ -f /etc/conf.d/mysql ]] && source /etc/conf.d/mysql - - # myservice={mysql,mysql-500,mysql-500_1} => {,-500,-500_1,-500.1} - local srv="${myservice#mysql}" - # srv={,-500,-500_1,-500.1} => {,500,500_1,500.1} - srv="${srv:1}" - # srv=array(0 => [srv_slot], 1 => [srv_num] ) - srv=( ${srv//[_.-]/" "} ) - local srv_slot=${srv[0]} srv_num=${srv[1]} - # defined in /etc/conf.d/mysql mysql_slot_{0,500,500_1} - local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]" - local conf_d_parameters="${!tmp_eval}" - MY_SUFFIX="-${srv_slot}" - if [[ -z "${srv_slot}" ]] ; then - srv_slot="0" - MY_SUFFIX='' - # try some other default for the default server - [[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=${mysql_slot_0[@]} - [[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=${mysql_slot[@]} - fi - [[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=( ) - basedir="" datadir="" pidfile="" socket="" - CHROOT="" NICE="" STARTUPTIMEOUT=5 STOPTIMEOUT=120 - - wdebug 3 "myservice ${myservice}" - wdebug 3 "srv ${srv[@]}" - wdebug 3 "srv_slot ${srv_slot}" - wdebug 3 "srv_num ${srv_num}" - wdebug 3 "tmp_eval ${tmp_eval}" - wdebug 3 "conf_d_parameters ${conf_d_parameters[@]}" - wdebug 3 "MY_SUFFIX ${MY_SUFFIX}" - - local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]" - local conf_d_parameters="${!tmp_eval}" - # collations need to be defined *after* the character sets, - #>so we will duplicate them - local collations="" - [[ ${conf_d_parameters[*]} == '()' ]] && conf_d_parameters='' - - MY_CNF="/etc/mysql${MY_SUFFIX}/my.cnf" - # summa of unmanaged parameters - #>some parameters may be present multiple times - unmanagedparams="" - - # grab the parameters from conf.d/mysql definition - for my_default in ${conf_d_parameters[*]}; do - case "${my_default}" in - nice=*) - NICE="${my_default#nice=}" - nice -n $NICE ls /tmp &>/dev/null || NICE="" - ;; - mycnf=*) MY_CNF="${my_default#mycnf=}" ;; - startup_timeout=*) - STARTUPTIMEOUT="${my_default#startup_timeout=}" ;; - stop_timeout=*) - STOPTIMEOUT="${my_default#stop_timeout=}" ;; - basedir=*) basedir="${my_default#basedir=}" ;; - datadir=*) datadir="${my_default#datadir=}" ;; - pid-file=*) pidfile="${my_default#pid-file=}" ;; - socket=*) socket="${my_default#socket=}" ;; - *collation*=) - collations="${collations} --$( do_escape "${my_default}" )" - ;; - *=*) - # list of parameters we already have - # prepend "--" because my_print_defaults do it - unmanagedparams="${unmanagedparams} --$( do_escape "${my_default}" )" - ;; - *) - unmanagedparams="${unmanagedparams} --${my_default}" - ;; - esac - done - - if [[ ! -r "${MY_CNF}" ]]; then - ewarn "Cannot access ${MY_CNF} !" - MY_CNF="" - my_defaults="" - else - local my_print_defaults="$(which my_print_defaults${MY_SUFFIX} 2>/dev/null)" - if [[ ! -x "${my_print_defaults}" ]]; then - eerror "my_print_defaults NOT found or not executable" - my_defaults="" - else - my_defaults=$( ${my_print_defaults} \ - --loose-verbose \ - --config-file="${MY_CNF}" \ - mysqld server ) - fi - fi - - # grab needed parameters from my.cnf, don't override the ones from - # conf.d mysql - for my_default in ${my_defaults}; do - case "${my_default}" in - --basedir=*) - [[ -z "${basedir}" ]] && basedir="${my_default#--basedir=}" ;; - --datadir=*) - [[ -z "${datadir}" ]] && datadir="${my_default#--datadir=}" ;; - --pid-file=*) - [[ -z "${pidfile}" ]] && pidfile="${my_default#--pid-file=}" ;; - --socket=*) - [[ -z "${socket}" ]] && socket="${my_default#--socket=}" ;; - --*collation*=) - # the order is inversed because we want the conf.d ones override - collations="$( do_escape "${my_default}" ) ${collations}" - ;; - esac - done - - # still empty, I'm in doubt if assign a default or break, will see - basedir="${basedir:-"/usr"}" - datadir="${datadir:-"/var/lib/mysql${MY_SUFFIX}"}" - pidfile="${pidfile:-"/var/run/mysqld/mysqld${MY_SUFFIX}.pid"}" - socket="${socket:-"/var/run/mysqld/mysqld${MY_SUFFIX}.sock"}" - unmanagedparams="${unmanagedparams} ${collations}" - - wdebug 3 "chroot dir => ${CHROOT}" - wdebug 3 "niceness => ${NICE}" - wdebug 3 "basedir => ${basedir}" - wdebug 3 "datadir => ${datadir}" - wdebug 3 "pidfile => ${pidfile}" - wdebug 3 "socket => ${socket}" - wdebug 3 "Unamanged => ${unmanagedparams}" - - # extension for sleep tenth of seconds, not very portable so check it before - if sleep 0.01 ; then - STARTUPTIMEOUT=$(( STARTUPTIMEOUT * 10 )) - STOPTIMEOUT=$(( STOPTIMEOUT * 10 )) - TIMEUNIT=0.1 - else - TIMEUNIT=1 - fi - - # push these out to the script - export MY_SUFFIX NICE MY_CNF pidfile datadir basedir socket CHROOT - export unmanagedparams STARTUPTIMEOUT STOPTIMEOUT TIMEUNIT - wdebug 4 "<<< get_slot_config() ok" - return 0 -} - -checkconfig() { - [[ -n "${NOCHECK}" ]] && return 0 - wdebug 4 ">>> checkconfig(\"${1}\")" - local datadir="$1" - if [ ! -d "${datadir}" ]; then - eerror "MySQL datadir is empty or invalid" - eerror "Please check your my.cnf : ${MY_CNF}" - wdebug 4 "<<< checkconfig() KO" - return 1 - fi - - if [ ! -d "$datadir/mysql" ]; then - eerror "You don't appear to have the mysql database installed yet." - eerror "Please run /usr/bin/mysql_install_db to have this done..." - wdebug 4 "<<< checkconfig() KO" - return 1 - fi - wdebug 4 "<<< checkconfig() ok" - return 0 -} - -start() { - wdebug 4 ">>> start()" - - local retstatus=0 - - ebegin - get_slot_config || return 1 - - if [[ -f ${pidfile} ]] || [[ -S ${socket} ]] ; then - echo "\"${pidfile}\" and/or \"${socket}\" are still present." - echo "Please check that no server is running and remove them." - return 1 - fi - - checkconfig "${datadir}" || return 2 - - einfo "Starting ${myservice} (${MY_CNF})" - - wdebug 2 "starting mysqld with: ${MY_CNF:+"--defaults-file="}${MY_CNF} ${unmanagedparams} --basedir=${basedir} --datadir=${datadir} --pid-file=${pidfile} --socket=${socket}" - - start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --start --background \ - ${NICE:+"--nicelevel "}${NICE} \ - --exec ${basedir}/sbin/mysqld${MY_SUFFIX} \ - -- \ - ${MY_CNF:+"--defaults-file="}${MY_CNF} \ - ${unmanagedparams} \ - --basedir=${basedir} \ - --datadir=${datadir} \ - --pid-file=${pidfile} \ - --socket=${socket} - - retstatus=$? - - # wait for socket creation - wdebug 1 - while ! [[ -S "${socket}" || "${STARTUPTIMEOUT}" -lt 1 || "${retstatus}" -ne 0 ]] ; do - STARTUPTIMEOUT=$(( STARTUPTIMEOUT - 1 )) - [[ ${DEBUG} -ge 1 ]] && echo -n "${STARTUPTIMEOUT}," - sleep ${TIMEUNIT} - done - wdebug 1 "" - if [[ ! -S "${socket}" ]] ; then - eerror "MySQL${MY_SUFFIX} NOT started (${retstatus})" - retstatus=1 - fi - - wdebug 4 "<<< start()" - eend $retstatus -} - -stop() { - get_slot_config - local retstatus=0 PID - local timeout=${STOPTIMEOUT:-"120"} - - PID=$(< "${pidfile}") - ebegin "Stopping ${myservice} (pid=${PID})" - - start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --stop --pidfile "${pidfile}" - wdebug 1 "" - while [[ -n "$PID" ]] \ - && $( kill -15 $PID 2>/dev/null ) \ - && [[ "${timeout}" -ge 1 ]] - do - timeout=$(($timeout - 1)) - [[ ${DEBUG} -ge 1 ]] && echo -n "$(( $STOPTIMEOUT - $timeout ))," - sleep ${TIMEUNIT} - done - [[ "${timeout}" -lt 1 ]] && retstatus=1 - eend ${retstatus} -} diff --git a/dev-db/mysql/files/mysql-slot.rc6-r3 b/dev-db/mysql/files/mysql-slot.rc6-r3 new file mode 100644 index 000000000000..f3c3ce8286a9 --- /dev/null +++ b/dev-db/mysql/files/mysql-slot.rc6-r3 @@ -0,0 +1,336 @@ +#!/sbin/runscript +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/files/mysql-slot.rc6-r3,v 1.1 2006/01/31 00:59:05 vivo Exp $ + +# external binaryes used: which, sed, tac + +# int in_list(char * elem, char * list) +function in_list() { + local elem=${1:-"none"} + local list=${2:-","} + + [[ "${list}" == "${list/,${elem},/}" ]] \ + && return 1 \ + || return 0 +} + +function wdebug() { + if [[ "${DEBUG}" -ge "${1}" ]] ; then + shift + echo "dbg: ${@}" + fi +} + +depend() { + use dns net localmount netmount nfsmount +} + +do_escape() { + # Ihatethisreallyverymuch + #echo "$1" | sed -e "s|'| |" -e "s|=|='|" -e "s|$|'|" + echo "$1" +} + +# int get_slot_config(srv_slot=0, srv_num) +get_slot_config() { + wdebug 4 ">>> get_slot_config()" + + local srv srv_slot srv_num + srv_slot="${1:-"0"}" + srv_num="${2}" + MY_SUFFIX="-${srv_slot}" + # srv=array(0 => [srv_slot], 1 => [srv_num] ) + srv=( ${srv_slot} ${srv_num} ) + + local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]" + local conf_d_parameters="${!tmp_eval}" + if [[ "${srv_slot}" == "0" ]] ; then + MY_SUFFIX='' + # try some other default for the default server + [[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=${mysql_slot[@]} + fi + [[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=( ) + basedir="" datadir="" pidfile="" socket="" + CHROOT="" NICE="" STARTUPTIMEOUT=5 STOPTIMEOUT=120 + + wdebug 3 "srv ${srv[@]}" + wdebug 3 "srv_slot ${srv_slot}" + wdebug 3 "srv_num ${srv_num}" + wdebug 3 "tmp_eval ${tmp_eval}" + wdebug 3 "conf_d_parameters ${conf_d_parameters[@]}" + wdebug 3 "MY_SUFFIX ${MY_SUFFIX}" + + local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]" + local conf_d_parameters="${!tmp_eval}" + # collations need to be defined *after* the character sets, + #>so we will duplicate them + local collations="" + [[ ${conf_d_parameters[*]} == '()' ]] && conf_d_parameters='' + + MY_CNF="/etc/mysql${MY_SUFFIX}/my.cnf" + # summa of unmanaged parameters + #>some parameters may be present multiple times + unmanagedparams="" + + # grab the parameters from conf.d/mysql definition + for my_default in ${conf_d_parameters[*]}; do + case "${my_default}" in + nice=*) + NICE="${my_default#nice=}" + nice -n $NICE ls /tmp &>/dev/null || NICE="" + ;; + mycnf=*) MY_CNF="${my_default#mycnf=}" ;; + startup_timeout=*) + STARTUPTIMEOUT="${my_default#startup_timeout=}" ;; + basedir=*) basedir="${my_default#basedir=}" ;; + datadir=*) datadir="${my_default#datadir=}" ;; + pid-file=*) pidfile="${my_default#pid-file=}" ;; + socket=*) socket="${my_default#socket=}" ;; + *collation*=) + collations="${collations} --$( do_escape "${my_default}" )" + ;; + *=*) + # list of parameters we already have + # prepend "--" because my_print_defaults do it + unmanagedparams="${unmanagedparams} --$( do_escape "${my_default}" )" + ;; + *) + unmanagedparams="${unmanagedparams} --${my_default}" + ;; + esac + done + + if [[ ! -r "${MY_CNF}" ]]; then + ewarn "Cannot access ${MY_CNF} !" + MY_CNF="" + my_defaults="" + else + local my_print_defaults="$(which my_print_defaults${MY_SUFFIX} 2>/dev/null)" + if [[ ! -x "${my_print_defaults}" ]]; then + eerror "my_print_defaults NOT found or not executable" + my_defaults="" + else + my_defaults=$( ${my_print_defaults} \ + --loose-verbose \ + --config-file="${MY_CNF}" \ + mysqld server ) + fi + fi + + # grab needed parameters from my.cnf, don't override the ones from + # conf.d mysql + for my_default in ${my_defaults}; do + case "${my_default}" in + --basedir=*) + [[ -z "${basedir}" ]] && basedir="${my_default#--basedir=}" ;; + --datadir=*) + [[ -z "${datadir}" ]] && datadir="${my_default#--datadir=}" ;; + --pid-file=*) + [[ -z "${pidfile}" ]] && pidfile="${my_default#--pid-file=}" ;; + --socket=*) + [[ -z "${socket}" ]] && socket="${my_default#--socket=}" ;; + --*collation*=) + # the order is inversed because we want the conf.d ones override + collations="$( do_escape "${my_default}" ) ${collations}" + ;; + esac + done + + # still empty, I'm in doubt if assign a default or break, will see + basedir="${basedir:-"/usr"}" + datadir="${datadir:-"/var/lib/mysql${MY_SUFFIX}"}" + pidfile="${pidfile:-"/var/run/mysqld/mysqld${MY_SUFFIX}.pid"}" + socket="${socket:-"/var/run/mysqld/mysqld${MY_SUFFIX}.sock"}" + unmanagedparams="${unmanagedparams} ${collations}" + + wdebug 3 "chroot dir => ${CHROOT}" + wdebug 3 "niceness => ${NICE}" + wdebug 3 "basedir => ${basedir}" + wdebug 3 "datadir => ${datadir}" + wdebug 3 "pidfile => ${pidfile}" + wdebug 3 "socket => ${socket}" + wdebug 3 "Unamanged => ${unmanagedparams}" + + # extension for sleep tenth of seconds, not very portable so check it before + if sleep 0.01 ; then + STARTUPTIMEOUT=$(( STARTUPTIMEOUT * 10 )) + STOPTIMEOUT=$(( STOPTIMEOUT * 10 )) + TIMEUNIT=0.1 + else + TIMEUNIT=1 + fi + + # push these out to the script + export MY_SUFFIX NICE MY_CNF pidfile datadir basedir socket CHROOT + export unmanagedparams STARTUPTIMEOUT STOPTIMEOUT TIMEUNIT + wdebug 4 "<<< get_slot_config() ok" + return 0 +} + +checkconfig() { + [[ -n "${NOCHECK}" ]] && return 0 + wdebug 4 ">>> checkconfig(\"${1}\")" + local datadir="$1" + if [ ! -d "${datadir}" ]; then + eerror "MySQL datadir is empty or invalid" + eerror "Please check your my.cnf : ${MY_CNF}" + wdebug 4 "<<< checkconfig() KO" + return 1 + fi + + if [ ! -d "$datadir/mysql" ]; then + eerror "You don't appear to have the mysql database installed yet." + eerror "Please run /usr/bin/mysql_install_db to have this done..." + wdebug 4 "<<< checkconfig() KO" + return 1 + fi + wdebug 4 "<<< checkconfig() ok" + return 0 +} + +start() { + wdebug 4 ">>> start()" + + MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-mysqld"} + # servers are defined in /etc/conf.d/mysql + local serverlist=${!mysql_slot_*} + # provide default for empty conf.d/mysql + if [[ -z "${serverlist}" ]] ; then + serverlist=0 + export mysql_slot_0=( ) + fi + local retstatus timeout + local globretstatus=1 + local srv_slot srv_num + # server MUST NOT share same location for these + local pidfilelist=',' datadirlist=',' socketlist=',' + local ssd_thing=1 + local mysqld_thing + + ebegin + # try to start each server + for srv in ${serverlist[*]} ; do + + srv_slot="${srv#mysql_slot_}" + if [[ "${srv_slot}" == "${srv_slot#*_}" ]] ; then + srv_num='' + else + srv_num="${srv_slot#*_}" + fi + srv_slot="${srv_slot%%_*}" + + retstatus=0 + get_slot_config "${srv_slot}" "${srv_num}" || retstatus=1 + + if [[ -f ${pidfile} ]] || [[ -S ${socket} ]] ; then + echo "\"${pidfile}\" and/or \"${socket}\" are still present." + echo "Please check that no server is running and remove them." + retstatus=1 ; continue + fi + + # pre_run checks + [[ "$retstatus" -eq 0 ]] && checkconfig "${datadir}" || retstatus=2 + if [[ "$retstatus" -eq 0 ]] ; then + if in_list "${pidfile}" "${pidfilelist}" ; then + eerror "Sorry, won't start with same pid-file: ${pidfile}" + retstatus=3 ; continue + fi + if in_list "${datadir}" "${datadirlist}" ; then + eerror "Sorry, won't start with same datadir: ${datadir}" + retstatus=4 ; continue + fi + if in_list "${socket}" "${socketlist}" ; then + eerror "Sorry, won't start with same socket: ${socket}" + retstatus=5 ; continue + fi + fi + + if ! checkconfig "${datadir}" ; then + retstatus=6 ; continue + fi + + einfo "Starting ${myservice} (${MY_CNF})" + + mysqld_thing="${MY_CNF:+"--defaults-file="}${MY_CNF}" + mysqld_thing="${mysqld_thing} ${unmanagedparams}" + mysqld_thing="${mysqld_thing} --basedir=${basedir}" + mysqld_thing="${mysqld_thing} --datadir=${datadir}" + mysqld_thing="${mysqld_thing} --pid-file=${pidfile}" + mysqld_thing="${mysqld_thing} --socket=${socket}" + + wdebug 2 "starting mysqld with: ${mysqld_thing}" + + if [[ ${ssd_thing} -eq 1 ]] ; then + start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --start \ + --background ${NICE:+"--nicelevel "}${NICE} \ + --exec ${basedir}/sbin/mysqld${MY_SUFFIX} -- ${mysqld_thing} + retstatus=$? + else + ${basedir}/sbin/mysqld${MY_SUFFIX} ${mysqld_thing} & + retstatus=0 + fi + + # only the first run is done by start-stop-daemon + ssd_thing="" + + # wait for socket creation + wdebug 1 + while ! [[ -S "${socket}" || "${STARTUPTIMEOUT}" -lt 1 || "${retstatus}" -ne 0 ]] ; do + STARTUPTIMEOUT=$(( STARTUPTIMEOUT - 1 )) + [[ ${DEBUG} -ge 1 ]] && echo -n "${STARTUPTIMEOUT}," + sleep ${TIMEUNIT} + done + wdebug 1 "" + if [[ ! -S "${socket}" ]] ; then + eerror "MySQL${MY_SUFFIX} NOT started (${retstatus})" + retstatus=1 + else + globretstatus=0 + pidfilelist="${pidfilelist}${pidfile}," + datadirlist="${datadirlist}${datadir}," + socketlist="${socketlist}${socket}," + echo "${srv_slot}${srv_num:+"_"}${srv_num}=${pidfile}" >> "${MYSQL_GLOB_PID_FILE}" + fi + done + # successfull if at least one mysqld started + wdebug 4 "<<< start()" + eend $globretstatus +} + +stop() { + get_slot_config &> /dev/null + MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-mysqld"} + local runwhat pidfile shutdown_elem + local PID cnt timeout=${STOPTIMEOUT:-"120"} + local retstatus=0 + local shutdown_list="$(tac "${MYSQL_GLOB_PID_FILE}")" + + ebegin "Stopping ${myservice} (pid=${PID})" + for shutdown_elem in $shutdown_list; do + runwhat=${shutdown_elem%%=*} + pidfile=${shutdown_elem#*=} + timeout=${STOPTIMEOUT:-"120"} + PID=$(< "${pidfile}" ) + wdebug 3 "runwhat ${runwhat}" + wdebug 3 "pidfile ${pidfile}" + wdebug 3 "timeout ${timeout}" + wdebug 3 "PID ${PID}" + + einfo "Stopping mysqld (${runwhat})" + + start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --stop --pidfile "${pidfile}" & + wdebug 1 "" + while [[ -n "$PID" ]] \ + && $( kill -15 $PID 2>/dev/null ) \ + && [[ "${timeout}" -ge 1 ]] + do + timeout=$(($timeout - 1)) + [[ ${DEBUG} -ge 1 ]] && echo -n "$(( $STOPTIMEOUT - $timeout ))," + sleep ${TIMEUNIT} + done + [[ "${timeout}" -lt 1 ]] && retstatus=1 + done + [[ "$retstatus" -eq 0 ]] && rm -f "$MYSQL_GLOB_PID_FILE" + eend ${retstatus} +} -- cgit v1.2.3-65-gdbad