Date: Fri, 21 Sep 2012 18:47:01 GMT From: Frank Wall <fw@moov.de> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/171852: [PATCH] databases/mysql55-server: add support for multiple instances (profiles) Message-ID: <201209211847.q8LIl1TN026888@red.freebsd.org> Resent-Message-ID: <201209211850.q8LIo8bN002843@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 171852 >Category: ports >Synopsis: [PATCH] databases/mysql55-server: add support for multiple instances (profiles) >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 Sep 21 18:50:08 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Frank Wall >Release: 7.4-RELEASE-p9 >Organization: >Environment: FreeBSD XXX 7.4-RELEASE-p9 FreeBSD 7.4-RELEASE-p9 #0: Mon Jun 11 19:47:58 UTC 2012 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64 >Description: This patch adds support for multiple MySQL instances ("profiles"). It's based upon the profile support in databases/postgresql91-server. It does NOT violate POLA, because the ports works the same until you define mysql_profiles="a b c" in /etc/rc.conf. This patch changes two things among the profile support: 1.) Add "mysql_bindip" tunable to allow profiles to bind to different IP addresses. It defaults to 0.0.0.0, just like not defining it at all. 2.) Add "mysql_port" tunable to allow profiles to listen on different TCP ports. It defaults to 3306, of course. 3.) In case profile support is enabled, make sure either "mysql_bindip" or "mysql_port" is defined to avoid having multiple profiles using the same (conflicting) default configuration. You may wonder: "Why add profile support? There is mysqld_multi included!" Well, mysqld_multi does not handle startup and shutdown of instances on system startup/shutdown. The approach of using profiles will just do that. And it's proven to work, since profiles are already used in databases/postgresql91-server and www/apache22. In case you agree to commit this patch I would provide a patch for databases/mysql51-server with a new PR. >How-To-Repeat: apply the patch >Fix: Patch attached with submission follows: --- databases/mysql55-server/files/mysql-server.in.orig 2012-09-20 16:26:05.550514234 +0200 +++ databases/mysql55-server/files/mysql-server.in 2012-09-21 20:30:00.783520896 +0200 @@ -1,6 +1,6 @@ #!/bin/sh # -# $FreeBSD: ports/databases/mysql55-server/files/mysql-server.in,v 1.1 2012/08/05 23:19:36 dougb Exp $ +# $FreeBSD$ # # PROVIDE: mysql @@ -11,13 +11,19 @@ # Add the following line to /etc/rc.conf to enable mysql: # mysql_enable (bool): Set to "NO" by default. # Set it to "YES" to enable MySQL. +# mysql_profiles (str): Set to "" by default. +# Define your profiles here. # mysql_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" # Base database directory. -# mysql_pidfile (str): Custum PID file path and name. +# mysql_pidfile (str): Custom PID file path and name. # Default to "${mysql_dbdir}/${hostname}.pid". +# mysql_bindip (str): Custom IP address to bind to. +# Default is 0.0.0.0. +# mysql_port (str): Custom port number. +# Default is 3306. # mysql_args (str): Custom additional arguments to be passed # to mysqld_safe (default empty). # @@ -32,16 +38,78 @@ : ${mysql_enable="NO"} : ${mysql_limits="NO"} : ${mysql_dbdir="/var/db/mysql"} +: ${mysql_user="mysql"} +: ${mysql_bindip="0.0.0.0"} +: ${mysql_port="3306"} -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" mysql_install_db="%%PREFIX%%/bin/mysql_install_db" + +if [ -n "$2" ]; then + profile="$2" + if [ "x${mysql_profiles}" != "x" ]; then + eval _bindip="\${mysql_${profile}_bindip}" + eval _port="\${mysql_${profile}_port}" + if [ "x$_bindip" = "x" ] && [ "x$_port" = "x" ]; then + echo "You must define either \"mysql_${profile}_port\" or \"mysql_${profile}_bindip\"" + exit 1 + fi + + eval mysql_enable="\${mysql_${profile}_enable:-${mysql_enable}}" + eval mysql_dbdir="\${mysql_${profile}_dbdir:-"/var/db/mysql-profile/${profile}"}" + eval pidfile="\${mysql_${profile}_pidfile:-"${mysql_dbdir}/${profile}.pid"}" + eval mysql_bindip="\${mysql_${profile}_bindip:-${mysql_bindip}}" + eval mysql_port="\${mysql_${profile}_port:-${mysql_port}}" + eval mysql_user="\${mysql_${profile}_user:-${mysql_user}}" + eval mysql_limits="\${mysql_${profile}_limits:-${mysql_limits}}" + eval mysql_args="\${mysql_${profile}_args:-${mysql_args}}" + else + echo "$0: extra argument ignored" + fi +else + eval mysql_envvars=${envvars} + if [ "x${mysql_profiles}" != "x" -a "x$1" != "x" ]; then + for profile in ${mysql_profiles}; do + eval _enable="\${mysql_${profile}_enable}" + case "x${_enable:-${mysql_enable}}" in + x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee]) + continue + ;; + x[Yy][Ee][Ss]) + ;; + *) + if test -z "$_enable"; then + _var=mysql_enable + else + _var=mysql_"${profile}"_enable + fi + echo "Bad value" \ + "'${_enable:-${mysql_enable}}'" \ + "for ${_var}. " \ + "Profile ${profile} skipped." + continue + ;; + esac + echo "===> mysql profile: ${profile}" + /usr/local/etc/rc.d/mysql-server $1 ${profile} + retcode="$?" + if [ "0${retcode}" -ne 0 ]; then + failed="${profile} (${retcode}) ${failed:-}" + else + success="${profile} ${success:-}" + fi + done + exit 0 + fi +fi + +# Construct arguments after the profile configuration has been processed. +command_args="-c -f %%PREFIX%%/bin/mysqld_safe --defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} --bind-address=${mysql_bindip} --port=${mysql_port} ${mysql_args}" mysql_install_db_args="--basedir=%%PREFIX%% --datadir=${mysql_dbdir} --force" mysql_create_auth_tables() >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209211847.q8LIl1TN026888>