Bug #75407 RFE - Modify init.d using --defaults-file
Submitted: 5 Jan 2015 8:12 Modified: 5 Dec 2016 7:03
Reporter: Javier Barroso Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.6 OS:Linux
Assigned to: Terje Røsten CPU Architecture:Any
Tags: init.d

[5 Jan 2015 8:12] Javier Barroso
Description:
Hello,

From init.d script I can see:

get_mysql_option(){
        result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
        if [ -z "$result" ]; then
            # not found, use default
            result="$3"
        fi
}

get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
...
        $exec   --datadir="$datadir" --socket="$socketfile" \
                --pid-file="$mypidfile" \
                --basedir=/usr --user=mysql >/dev/null 2>&1 &

...

Why do you not use --defaults-file=my.cnf as parameter (and remove get_mysql_option function) ?

I would add a comment at header , telling about modify  #config and #pidfile manually if you decide to have some new flavour of mysql

I'm attaching a patch (I tried to be the less intrusive possible ( I think some of options to $exec line could be removed ))

Thank you

How to repeat:
Make easy if you want to have various instances of mysql running on the same server.

See that may be better option is adding an parameter which indicates the flavour:

/etc/init.d/mysqld myflavour start 

But then we should search what to start if you call it without any flavour (maybe all instances at /etc/my-*), but I don't think it would be a good idea

Thank you

Suggested fix:
--- /etc/init.d/mysqld	2014-12-30 16:22:56.000000000 +0100
+++ /etc/init.d/mysqld-defaults	2015-01-05 09:03:17.680004647 +0100
@@ -17,7 +17,15 @@
 
 
 exec="/usr/bin/mysqld_safe"
-prog="mysqld"
+flavour=""
+if [ -n "$flavour" ]
+then
+	prog="mysqld-$flavour"
+	conf="/etc/my-$flavour.cnf"
+else
+	prog="mysqld"
+	conf="/etc/my.cnf"
+fi
 
 # Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
 STARTTIMEOUT=120
@@ -34,7 +42,7 @@
 # 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(){
-	result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
+	result=`/usr/bin/my_print_defaults -c"$conf" "$1" | sed -n "s/^--$2=//p" | tail -n 1`
 	if [ -z "$result" ]; then
 	    # not found, use default
 	    result="$3"
@@ -100,8 +108,8 @@
 	# and some users might prefer to configure logging to syslog.)
 	# Note: set --basedir to prevent probes that might trigger SELinux
 	# alarms, per bug #547485
-	$exec   --datadir="$datadir" --socket="$socketfile" \
-		--pid-file="$mypidfile" \
+	$exec   --defaults-file="$conf" --datadir="$datadir" --socket="$socketfile" \
+		--pid-file="$mypidfile" --ignore-db-dir="lost+found" \
 		--basedir=/usr --user=mysql >/dev/null 2>&1 &
 	safe_pid=$!
 	# Spin for a maximum of N seconds waiting for the server to come up;
[4 Dec 2016 22:11] Terje Røsten
hi!

> Why do you not use --defaults-file=my.cnf as parameter 
> (and remove get_mysql_option function) ?

get_mysql_option is used to get specific *option* from the config file,
--defaults-file just tells which config *file* to use.

By adding --defaults-file="$conf" even if $conf=/etc/my.cnf is changing things.

When --defaults-file is used, *only* this config file given will be used, without -defaults-file, several files will parsed and used, from my_print_default help text:

   Default options are read from the following files in the given order:
     /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

Any way, SysV initscripts is almost legacy these days, on platforms with systemd support, more advanced multi instance/flavour options are already available, see  manual for a introduction:
 
 https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

Here is example of such set up:

  http://thesubtlepath.com/blog/mysql/mysql-multi-instance-group-replication-on-systemd/

Is this good enough to cover your needs?
[4 Dec 2016 22:28] Javier Barroso
Hello,

Yes, with systemd this issue is obsolete. When I wrote this rfe I forgot about my.conf alternatives location.

Thank you for take caring about
PD: Please close this "bug"