Bug #84219 initscript errors when lauching mysqld_safe in non default basedir
Submitted: 15 Dec 2016 16:13 Modified: 3 Mar 2017 2:00
Reporter: Leandro Morgado Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.6.35 OS:Linux
Assigned to: Terje Røsten CPU Architecture:Any

[15 Dec 2016 16:13] Leandro Morgado
Description:
It seems some changes introduced in 5.6.35 broke the initscript. 
It works fine in 5.6.34 but can not find mysqld in 5.6.35.  I suspect due to this change described below. A simple workaround (adding --ledir to the initscript) has been provided. 
=========
Incompatible Change: These changes were made to mysqld_safe:

Unsafe use of rm and chown in mysqld_safe could result in privilege escalation. chown now can be used only when the target directory is /var/log. An incompatible change is that if the directory for the Unix socket file is missing, it is no longer created; instead, an error occurs. Due to these changes, /bin/bash is required to run mysqld_safe on Solaris. /bin/sh is still used on other Unix/Linux platforms.

The --ledir option now is accepted only on the command line, not in option files.

mysqld_safe ignores the current working directory.

Other related changes:

Initialization scripts that invoke mysqld_safe pass --basedir explicitly.

Initialization scripts create the error log file only if the base directory is /var/log or /var/lib.

Unused systemd files for SLES were removed.

(Bug #24483092, Bug #25088048)

References: See also: Bug #24464380, Bug #24388753.
  https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-35.html
=========

How to repeat:
# using 5.6.34 it works fine
root@debian:/opt# ln -s mysql-advanced-5.6.34-linux-glibc2.5-x86_64/ mysql
root@debian:/opt# ls -la
total 16
drwxr-xr-x  4 root root  4096 Dec 15 15:37 .
drwxr-xr-x 24 root root  4096 Dec 14 17:20 ..
lrwxrwxrwx  1 root root    44 Dec 15 15:37 mysql -> mysql-advanced-5.6.34-linux-glibc2.5-x86_64/
drwxr-xr-x 13 root mysql 4096 Dec 15 14:48 mysql-advanced-5.6.34-linux-glibc2.5-x86_64
drwxr-xr-x 13 root mysql 4096 Dec 15 14:54 mysql-advanced-5.6.35-linux-glibc2.5-x86_64

# setup values for non default basedir/datadir
root@debian:/opt/mysql# grep ^basedir /etc/init.d/mysql
basedir=/opt/mysql
root@debian:/opt/mysql# grep ^datadir /etc/init.d/mysql
datadir=/opt/mysql/data
datadir_set=

# my.cnf file
root@debian:/opt/mysql# cat /etc/my.cnf 
[mysqld_safe]
basedir=/opt/mysql

#start 5.6.34 and stop
root@debian:/opt/mysql# /etc/init.d/mysql status
[FAIL] MySQL is not running ... failed!
root@debian:/opt/mysql# /etc/init.d/mysql start
Starting MySQL
[.ok 
root@debian:/opt/mysql# /etc/init.d/mysql status
[ ok ] MySQL running (8042).
root@debian:/opt/mysql# /opt/mysql/bin/mysql -e "select version();"
+---------------------------------------+
| version()                             |
+---------------------------------------+
| 5.6.34-enterprise-commercial-advanced |
+---------------------------------------+
root@debian:/opt/mysql# /etc/init.d/mysql stop
Shutting down MySQL
[ .k 

#now change to 5.6.35
root@debian:/opt# rm mysql
root@debian:/opt# ln -s mysql-advanced-5.6.35-linux-glibc2.5-x86_64/ mysql
root@debian:/opt# ls -lah
total 16K
drwxr-xr-x  4 root root  4.0K Dec 15 15:42 .
drwxr-xr-x 24 root root  4.0K Dec 14 17:20 ..
lrwxrwxrwx  1 root root    44 Dec 15 15:42 mysql -> mysql-advanced-5.6.35-linux-glibc2.5-x86_64/
drwxr-xr-x 13 root mysql 4.0K Dec 15 14:48 mysql-advanced-5.6.34-linux-glibc2.5-x86_64
drwxr-xr-x 13 root mysql 4.0K Dec 15 14:54 mysql-advanced-5.6.35-linux-glibc2.5-x86_64

# init script fails to start mysqld 5.6.35
root@debian:/opt/mysql# /etc/init.d/mysql status
[FAIL] MySQL is not running ... failed!
root@debian:/opt/mysql# /etc/init.d/mysql start
Starting MySQL
.161215 15:42:59 mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
[FAIL] The server quit without updating PID file (/opt/mysql/data/debian.pid). ... failed!

# If we modify init script to pass --ledir to mysqld_safe, it works 
#
root@debian:/etc# cp -a /etc/init.d/mysql /etc/init.d/mysql5634
root@debian:/etc# vim /etc/init.d/mysql
...
root@debian:/etc# diff -u /etc/init.d/mysql /etc/init.d/mysql5634
--- /etc/init.d/mysql	2016-12-15 15:56:59.947018777 +0000
+++ /etc/init.d/mysql5634	2016-12-15 15:51:55.995015143 +0000
@@ -280,7 +280,7 @@
     then
       # Give extra arguments to mysqld with the my.cnf file. This script
       # may be overwritten at next upgrade.
-      $bindir/mysqld_safe --ledir="$bindir" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
+      $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
       wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
 
root@debian:/opt/mysql# /etc/init.d/mysql status
[FAIL] MySQL is not running, but PID file exists ... failed!
root@debian:/opt/mysql# /etc/init.d/mysql start
Starting MySQL
. ok 
root@debian:/opt/mysql# /opt/mysql/bin/mysql -e "select version();"
+---------------------------------------+
| version()                             |
+---------------------------------------+
| 5.6.35-enterprise-commercial-advanced |
+---------------------------------------+
root@debian:/opt/mysql# /etc/init.d/mysql stop
Shutting down MySQL
[ .k 

Suggested fix:
The initscript should still work with 5.6.35 without users needing to manually edit it and hack a fix with mysqld_safe --ledir=..
[15 Dec 2016 22:10] Terje Røsten
hi!

Thanks for your report!

Where did you get /etc/init.d/mysql from?

What is the contents of that file?
[15 Dec 2016 22:15] Leandro Morgado
Hi Terje,

The init file was copied from the tarball mysql-advanced-5.6.34-linux-glibc2.5-x86_64.tar, it's original location was support-files/mysql.server. The 5.6.35 version is exactly the same. The basedir and datadir variables were populated in both scripts. The .34 one works, the .35 will not work unless it has the "ledir hack". 
I'll attach both init scripts to the bug report.

Regards,
Leandro
[15 Dec 2016 22:16] Leandro Morgado
5.6.34 original script, with basedir and datadir populated

Attachment: mysql5634 (application/octet-stream, text), 10.64 KiB.

[15 Dec 2016 22:16] Leandro Morgado
5.6.35 script, with basedir and datadir populated + ledir hack

Attachment: mysql5635_ledirhack (application/octet-stream, text), 10.66 KiB.

[3 Mar 2017 2:00] Paul DuBois
Posted by developer:
 
Noted in 5.5.55, 5.6.36, 5.7.18, 8.0.1 changelogs.

Init scripts failed to launch mysqld_safe if a non-default base
directory was used.