diff options
author | Terje Rosten <terje.rosten@oracle.com> | 2016-11-16 13:41:27 +0100 |
---|---|---|
committer | Gipson Pulla <gipson.pulla@oracle.com> | 2016-11-25 14:54:08 +0530 |
commit | 53230ba274a37fa13d65e802c6ef3766cd0c6d91 (patch) | |
tree | 4fa18083afddaebcd58f914ea5755ba874f995f5 | |
parent | c3cf7f47f0f4a1ec314001aaf0c3d9c1c1f62097 (diff) | |
download | mariadb-git-53230ba274a37fa13d65e802c6ef3766cd0c6d91.tar.gz |
Bug#25088048 ADDITIONAL ISSUES IN MYSQLD_SAFE
Don't read --ledir option from config file.
Ignore current working for finding location of mysqld
Remove use of chown/chmod in scripts.
Be helpful only when basedir is /var/log or /var/lib.
Removed unused systemd files for SLES.
Set explicit basedir in scripts.
-rw-r--r-- | packaging/rpm-oel/mysql-systemd-start | 4 | ||||
-rw-r--r-- | packaging/rpm-oel/mysql.init | 24 | ||||
-rw-r--r-- | packaging/rpm-oel/mysqld.service | 2 | ||||
-rw-r--r-- | packaging/rpm-sles/CMakeLists.txt | 3 | ||||
-rw-r--r-- | packaging/rpm-sles/mysql-systemd-start | 66 | ||||
-rw-r--r-- | packaging/rpm-sles/mysql.conf | 1 | ||||
-rw-r--r-- | packaging/rpm-sles/mysql.init | 13 | ||||
-rw-r--r-- | packaging/rpm-sles/mysqld.service | 48 | ||||
-rw-r--r-- | scripts/mysqld_safe.sh | 18 |
9 files changed, 41 insertions, 138 deletions
diff --git a/packaging/rpm-oel/mysql-systemd-start b/packaging/rpm-oel/mysql-systemd-start index 231a76087ac..af6e906efe1 100644 --- a/packaging/rpm-oel/mysql-systemd-start +++ b/packaging/rpm-oel/mysql-systemd-start @@ -22,7 +22,9 @@ install_db () { datadir=$(get_option mysqld datadir "/var/lib/mysql") # Restore log, dir, perms and SELinux contexts - [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1 + if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then + install -d -m 0755 -omysql -gmysql "$datadir" || exit 1 + fi log=/var/log/mysqld.log [ -e $log ] || touch $log chmod 0640 $log diff --git a/packaging/rpm-oel/mysql.init b/packaging/rpm-oel/mysql.init index 75ae672801b..50d1bba017d 100644 --- a/packaging/rpm-oel/mysql.init +++ b/packaging/rpm-oel/mysql.init @@ -70,18 +70,19 @@ start(){ ret=0 else # prepare for start - touch "$errlogfile" - chown mysql:mysql "$errlogfile" - chmod 0640 "$errlogfile" + if [ ! -e "$errlogfile" -a ! -h "$errlogfile" -a "x$(dirname "$errlogfile")" = "x/var/log" ]; then + install /dev/null -m0640 -omysql -gmysql "$errlogfile" + fi [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" if [ ! -d "$datadir/mysql" ] ; then # First, make sure $datadir is there with correct permissions - if [ ! -e "$datadir" -a ! -h "$datadir" ] - then - mkdir -p "$datadir" || exit 1 + if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then + install -d -m0755 -omysql -gmysql "$datadir" || exit 1 + fi + if [ ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then + chown mysql:mysql "$datadir" + chmod 0755 "$datadir" fi - chown mysql:mysql "$datadir" - chmod 0755 "$datadir" if [ -x /sbin/restorecon ]; then /sbin/restorecon "$datadir" for dir in /var/lib/mysql-files ; do @@ -94,13 +95,14 @@ start(){ # Now create the database action $"Initializing MySQL database: " /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql ret=$? - chown -R mysql:mysql "$datadir" if [ $ret -ne 0 ] ; then return $ret fi fi - chown mysql:mysql "$datadir" - chmod 0755 "$datadir" + if [ ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then + chown mysql:mysql "$datadir" + chmod 0755 "$datadir" + fi # Pass all the options determined above, to ensure consistent behavior. # In many cases mysqld_safe would arrive at the same conclusions anyway # but we need to be sure. (An exception is that we don't force the diff --git a/packaging/rpm-oel/mysqld.service b/packaging/rpm-oel/mysqld.service index 78ef3bffe60..871f191c017 100644 --- a/packaging/rpm-oel/mysqld.service +++ b/packaging/rpm-oel/mysqld.service @@ -34,7 +34,7 @@ PermissionsStartOnly=true ExecStartPre=/usr/bin/mysql-systemd-start pre # Start main service -ExecStart=/usr/bin/mysqld_safe +ExecStart=/usr/bin/mysqld_safe --basedir=/usr # Don't signal startup success before a ping works ExecStartPost=/usr/bin/mysql-systemd-start post diff --git a/packaging/rpm-sles/CMakeLists.txt b/packaging/rpm-sles/CMakeLists.txt index b5ffaa15565..98aa4f4d222 100644 --- a/packaging/rpm-sles/CMakeLists.txt +++ b/packaging/rpm-sles/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ IF(UNIX) # Left in current directory, to be taken during build CONFIGURE_FILE(mysql.spec.in ${CMAKE_CURRENT_BINARY_DIR}/${SPECFILENAME} @ONLY) FOREACH(fedfile my.cnf my_config.h mysql.init - mysqld.service mysql-systemd-start mysql.conf filter-requires.sh filter-provides.sh) CONFIGURE_FILE(${fedfile} ${CMAKE_CURRENT_BINARY_DIR}/${fedfile} COPYONLY) ENDFOREACH() diff --git a/packaging/rpm-sles/mysql-systemd-start b/packaging/rpm-sles/mysql-systemd-start deleted file mode 100644 index 28472249eda..00000000000 --- a/packaging/rpm-sles/mysql-systemd-start +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/bash -# -# Scripts to run by MySQL systemd service -# -# Needed argument: pre | post -# -# pre mode : try to run mysql_install_db and fix perms and SELinux contexts -# post mode : ping server until answer is received -# - -install_db () { - # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode) - datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n 's/--datadir=//p' | tail -n 1) - - # Restore log, dir, perms and SELinux contexts - [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1 - log=/var/log/mysqld.log - [ -e $log ] || touch $log - chmod 0640 $log - chown mysql:mysql $log || exit 1 - if [ -x /usr/sbin/restorecon ]; then - /usr/sbin/restorecon "$datadir" - /usr/sbin/restorecon $log - fi - - # If special mysql dir is in place, skip db install - [ -d "$datadir/mysql" ] && exit 0 - - # Create initial db - /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql - - # Create a file to trigger execution of mysql_secure_installation - # after server has started - touch "$datadir"/.phase_two_required - - exit 0 -} - -pinger () { - # Wait for ping to answer to signal startup completed, - # might take a while in case of e.g. crash recovery - # MySQL systemd service will timeout script if no answer - ret=1 - while /bin/true ; do - sleep 1 - mysqladmin ping >/dev/null 2>&1 && ret=0 && break - done - - # If server has been started successfully and file created in - # install_db step is present we run mysql_secure_installation - if [ $ret -eq 0 -a -e "$datadir"/.phase_two_required -a -x /usr/bin/mysql_secure_installation ] ; then - /usr/bin/mysql_secure_installation --use-default --defaults-file=/etc/my.cnf - rm -f "$datadir"/.phase_two_required - fi - - exit 0 -} - -# main -case $1 in - "pre") install_db ;; - "post") pinger ;; -esac - -exit 0 - diff --git a/packaging/rpm-sles/mysql.conf b/packaging/rpm-sles/mysql.conf deleted file mode 100644 index 74cd5f836e7..00000000000 --- a/packaging/rpm-sles/mysql.conf +++ /dev/null @@ -1 +0,0 @@ -d /var/run/mysqld 0755 mysql mysql - diff --git a/packaging/rpm-sles/mysql.init b/packaging/rpm-sles/mysql.init index dda0bebba56..25762d9bee2 100644 --- a/packaging/rpm-sles/mysql.init +++ b/packaging/rpm-sles/mysql.init @@ -49,7 +49,6 @@ get_option () { datadir=$(get_option mysqld datadir "/var/lib/mysql") socket=$(get_option mysqld socket "$datadir/mysql.sock") pidfile=$(get_option mysqld_safe pid-file "/var/run/mysql/mysqld.pid") -logfile=$(get_option mysqld_safe log-error "/var/log/mysql/mysqld.log") install_db () { # Note: something different than datadir=/var/lib/mysql requires @@ -58,14 +57,16 @@ install_db () { logfile=$(get_option mysqld_safe log-error "/var/log/mysql/mysqld.log") # Restore log, dir, perms and SELinux contexts - [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || return 1 + if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then + install -d -m 0755 -omysql -gmysql "$datadir" || return 1 + fi - [ -e $logfile ] || touch $logfile || return 1 - chmod 0640 $logfile - chown mysql:mysql $logfile || return 1 + if [ ! -e "$logfile" -a ! -h "$logfile" -a "x$(dirname "$logfile")" = "x/var/log/mysql" ]; then + install /dev/null -omysql -gmysql "$logfile" || return 1 + fi if [ -x /usr/sbin/restorecon ]; then /usr/sbin/restorecon "$datadir" - /usr/sbin/restorecon $logfile + /usr/sbin/restorecon "$logfile" fi # If special mysql dir is in place, skip db install diff --git a/packaging/rpm-sles/mysqld.service b/packaging/rpm-sles/mysqld.service deleted file mode 100644 index 78ef3bffe60..00000000000 --- a/packaging/rpm-sles/mysqld.service +++ /dev/null @@ -1,48 +0,0 @@ -# -# Simple MySQL systemd service file -# -# systemd supports lots of fancy features, look here (and linked docs) for a full list: -# http://www.freedesktop.org/software/systemd/man/systemd.exec.html -# -# Note: this file ( /usr/lib/systemd/system/mysql.service ) -# will be overwritten on package upgrade, please copy the file to -# -# /etc/systemd/system/mysql.service -# -# to make needed changes. -# -# systemd-delta can be used to check differences between the two mysql.service files. -# - -[Unit] -Description=MySQL Community Server -After=network.target -After=syslog.target - -[Install] -WantedBy=multi-user.target -Alias=mysql.service - -[Service] -User=mysql -Group=mysql - -# Execute pre and post scripts as root -PermissionsStartOnly=true - -# Needed to create system tables etc. -ExecStartPre=/usr/bin/mysql-systemd-start pre - -# Start main service -ExecStart=/usr/bin/mysqld_safe - -# Don't signal startup success before a ping works -ExecStartPost=/usr/bin/mysql-systemd-start post - -# Give up if ping don't get an answer -TimeoutSec=600 - -Restart=always -PrivateTmp=false - - diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 4b103817ab6..a5c87a44e65 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -218,7 +218,13 @@ parse_arguments() { # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])! --core-file-size=*) core_file_size="$val" ;; - --ledir=*) ledir="$val" ;; + --ledir=*) + if [ -z "$pick_args" ]; then + log_error "--ledir option can only be used as command line option, found in config file" + exit 1 + fi + ledir="$val" + ;; --malloc-lib=*) set_malloc_lib "$val" ;; --mysqld=*) if [ -z "$pick_args" ]; then @@ -394,7 +400,15 @@ else relpkgdata='@pkgdatadir@' fi -MY_PWD=`pwd` +case "$0" in + /*) + MY_PWD='@prefix@' + ;; + *) + MY_PWD=`dirname $0` + MY_PWD=`dirname $MY_PWD` + ;; +esac # Check for the directories we would expect from a binary release install if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION" then |