Date: Fri, 17 May 2013 19:37:37 +0200 (CEST) From: Geoffroy Desvernay <dgeo@centrale-marseille.fr> To: FreeBSD-gnats-submit@freebsd.org Cc: flo@FreeBSD.org, ale@FreeBSD.org Subject: ports/178726: [PATCH] databases/mariadb-server: multi-instances startup script Message-ID: <20130517173737.45E7C1CD2C@dgeo.sysadm.ec-m.fr> Resent-Message-ID: <201305171750.r4HHo3eJ069614@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 178726 >Category: ports >Synopsis: [PATCH] databases/mariadb-server: multi-instances startup script >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri May 17 17:50:03 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Geoffroy Desvernay >Release: FreeBSD 9.1-STABLE amd64 >Organization: Ecole Centrale de Marseille >Environment: System: FreeBSD dgeo.sysadm.ec-m.fr 9.1-STABLE FreeBSD 9.1-STABLE #0: Fri May 3 23:40:18 CEST >Description: modify mysql-server script to allow multiple instances to be launched, as my old mariadb-server's port do ex. rc.conf: mysql_instances="one two" mysql_two_user="mytwo" mysql_two_dbdir="/data/mytwo" mysql_one_user="myone" mysql_one_dbdir="/data/myone" I merged "mysql_optfile" from mysql55-server, mariadb55-server's script and old one. This should not change behaviour of the script without instances (default is to use $mysql_* variables and to launch one server) I cc'd perconna and mysql's maintainers as this could be used as well with their ports. Let me know your thoughts about this (here we are using *many* unix-isolated instances instead of VM's or monolithic DB server since more than 10 years with this script) Port maintainer (never@nevermind.kiev.ua) is cc'd. Generated with FreeBSD Port Tools 0.99_7 (mode: change, diff: SVN) >How-To-Repeat: >Fix: --- mariadb-server-5.5.30.patch begins here --- Index: files/mysql-server.in =================================================================== --- files/mysql-server.in (revision 318393) +++ files/mysql-server.in (working copy) @@ -1,26 +1,29 @@ #!/bin/sh -# + # $FreeBSD$ # - # PROVIDE: mysql # REQUIRE: LOGIN # KEYWORD: shutdown - # # Add the following line to /etc/rc.conf to enable mysql: -# mysql_enable (bool): Set to "NO" by default. +# mysql_(instance_)?enable (bool): Set to "NO" by default. # Set it to "YES" to enable MySQL. -# mysql_limits (bool): Set to "NO" by default. +# mysql_(instance_)?limits (bool): Set to "NO" by default. # Set it to yes to run `limits -e -U mysql` # just before mysql starts. -# mysql_dbdir (str): Default to "/var/db/mysql" +# mysql_(instance_)?dbdir (str): Default to "/var/db/mysql" # Base database directory. -# mysql_pidfile (str): Custum PID file path and name. +# mysql_(instance_)?args (str): Custom additional arguments to be passed +# to mysqld_safe (default empty). +# mysql_(instance_)?pidfile (str): Custum PID file path and name. # Default to "${mysql_dbdir}/${hostname}.pid". -# mysql_args (str): Custom additional arguments to be passed -# to mysqld_safe (default empty). -# +# mysql_(instance_)?user (str): User to run mysqld as +# Default to "mysql" created by the port +# mysql_(instance_)?optfile (str): Server-specific option file. +# Default to "${mysql_dbdir}/my.cnf". +# mysql_instances (str): Set to "" by default. +# If defined, list of instances to enable . /etc/rc.subr @@ -31,23 +34,77 @@ : ${mysql_enable="NO"} : ${mysql_limits="NO"} +: ${mysql_user="mysql"} +: ${mysql_limits_args="-e -U $mysql_user"} : ${mysql_dbdir="/var/db/mysql"} +: ${mysql_optfile="${mysql_dbdir}/my.cnf"} -mysql_user="mysql" -mysql_limits_args="-e -U ${mysql_user}" -pidfile=${mysql_pidfile:-"${mysql_dbdir}/`/bin/hostname`.pid"} command="/usr/sbin/daemon" -command_args="-c -f %%PREFIX%%/bin/mysqld_safe --defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}" procname="%%PREFIX%%/libexec/mysqld" start_precmd="${name}_prestart" start_postcmd="${name}_poststart" + +if [ -n "$2" ]; then + instance="$2" + load_rc_config ${name}_${instance} + case "$mysql_instances" in + "$2 "*|*" $2 "*|*" $2"|"$2") + eval mysql_args="\${mysql_${instance}_args:-\"${mysql_args}\"}" + eval mysql_dbdir="\${mysql_${instance}_dbdir:-\"/var/db/mysql_${instance}\"}" + eval mysql_limits="\${mysql_${instance}_limits:-\"${mysql_limits}\"}" + eval mysql_user="\${mysql_${instance}_user:-\"${mysql_user}\"}" + eval mysql_limits_args="\${mysql_${instance}_limits_args:-\"-e -U $mysql_user\"}" + eval mysql_optfile="\${mysql_${instance}_optfile:-\"${mysql_dbdir}/my.cnf\"}" + eval mysql_pidfile="\${mysql_${instance}_pidfile:-\"${mysql_dbdir}/`/bin/hostname`.pid\"}" + ;; + *) + err 1 "$2 not found in mysql_instances" ;; + esac +else + if [ -n "${mysql_instances}" -a -n "$1" ]; then + for instance in ${mysql_instances}; do + eval _enable="\${mysql_${instance}_enable}" + case "${_enable:-${mysql_enable}}" in + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + continue + ;; + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + ;; + *) + if [ -z "$_enable" ]; then + _var=mysql_enable + else + _var=mysql_${instance}_enable + fi + warn "Bad value" \ + "'${_enable:-${mysql_enable}}'" \ + "for ${_var}. " \ + "Instance ${instance} skipped." + continue + ;; + esac + echo "===> mysql instance: ${instance}" + if %%PREFIX%%/etc/rc.d/mysql-server $1 ${instance}; then + success="${instance} ${success}" + else + failed="${instance} (${retcode}) ${failed}" + fi + done + exit 0 + else + mysql_pidfile=${mysql_pidfile:-"${mysql_dbdir}/`/bin/hostname`.pid"} + fi +fi + +pidfile=$mysql_pidfile mysql_install_db="%%PREFIX%%/bin/mysql_install_db" mysql_install_db_args="--basedir=%%PREFIX%% --datadir=${mysql_dbdir} --force" +command_args="-c -f %%PREFIX%%/bin/mysqld_safe --defaults-extra-file=${mysql_optfile} --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}" mysql_create_auth_tables() { - eval $mysql_install_db $mysql_install_db_args >/dev/null 2>/dev/null - [ $? -eq 0 ] && chown -R ${mysql_user}:${mysql_user} ${mysql_dbdir} + eval $mysql_install_db $mysql_install_db_args + [ $? -eq 0 ] && chown -R ${mysql_user}:$(id -gn $mysql_user) ${mysql_dbdir} } mysql_prestart() @@ -56,7 +113,7 @@ mysql_create_auth_tables || return 1 fi if checkyesno mysql_limits; then - eval `/usr/bin/limits ${mysql_limits_args}` 2>/dev/null + eval `/usr/bin/limits ${mysql_limits_args:-"-e -U $mysql_user"}` 2>/dev/null else return 0 fi --- mariadb-server-5.5.30.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130517173737.45E7C1CD2C>