diff --git a/mariadb-config.patch b/mariadb-config.patch new file mode 100644 index 0000000..5034890 --- /dev/null +++ b/mariadb-config.patch @@ -0,0 +1,20 @@ +Settings specific for MariaDB specific are defined in appropriate section in +/etc/my.cnf.d/server.cnf (part of mariadb-server). +It doesn't matter that we set these settings only for [mysqld] here, +because they will be read and used in mysqld_safe as well. +Settings in my.cnf are generic for all MySQL implementations because of +conflict issues. +RHBZ#1003115 + +diff -up mariadb-5.5.32/support-files/rpm/server.cnf.mariaconf mariadb-5.5.32/support-files/rpm/server.cnf +--- mariadb-5.5.32/support-files/rpm/server.cnf.mariaconf 2013-09-02 14:17:37.277833263 +0200 ++++ mariadb-5.5.32/support-files/rpm/server.cnf 2013-09-02 14:18:00.638810223 +0200 +@@ -23,6 +23,8 @@ + # If you use the same .cnf file for MySQL and MariaDB, + # you can put MariaDB-only options here + [mariadb] ++log-error=/var/log/mariadb/mariadb.log ++pid-file=/var/run/mariadb/mariadb.pid + + [mariadb-5.5] + diff --git a/mariadb-prepare-db-dir b/mariadb-prepare-db-dir new file mode 100644 index 0000000..8762ab7 --- /dev/null +++ b/mariadb-prepare-db-dir @@ -0,0 +1,82 @@ +#!/bin/sh + +# This script creates the mysql data directory during first service start. +# In subsequent starts, it does nothing much. + +# extract value of a MySQL option from config files +# Usage: get_mysql_option SECTION VARNAME DEFAULT +# result is returned in $result +# 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` + if [ -z "$result" ]; then + # not found, use default + result="$3" + fi +} + +# Defaults here had better match what mysqld_safe will default to +get_mysql_option mysqld datadir "/var/lib/mysql" +datadir="$result" +get_mysql_option mysqld_safe log-error "/var/log/mariadb/mariadb.log" +errlogfile="$result" + +# Absorb configuration settings from the specified systemd service file, +# or the default "mysqld" service if not specified +SERVICE_NAME="$1" +if [ x"$SERVICE_NAME" = x ] +then + SERVICE_NAME=mysqld.service +fi + +myuser=`systemctl show -p User "${SERVICE_NAME}" | + sed 's/^User=//'` +if [ x"$myuser" = x ] +then + myuser=mysql +fi + +mygroup=`systemctl show -p Group "${SERVICE_NAME}" | + sed 's/^Group=//'` +if [ x"$mygroup" = x ] +then + mygroup=mysql +fi + +# Set up the errlogfile with appropriate permissions +touch "$errlogfile" +chown "$myuser:$mygroup" "$errlogfile" +chmod 0640 "$errlogfile" +[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" + +# Make the data directory +if [ ! -d "$datadir/mysql" ] ; then + # First, make sure $datadir is there with correct permissions + # (note: if it's not, and we're not root, this'll fail ...) + if [ ! -e "$datadir" -a ! -h "$datadir" ] + then + mkdir -p "$datadir" || exit 1 + fi + chown "$myuser:$mygroup" "$datadir" + chmod 0755 "$datadir" + [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir" + + # Now create the database + echo "Initializing MySQL database" + /usr/bin/mysql_install_db --datadir="$datadir" --user="$myuser" + ret=$? + if [ $ret -ne 0 ] ; then + echo "Initialization of MySQL database failed." >&2 + echo "Perhaps /etc/my.cnf is misconfigured." >&2 + # Clean up any partially-created database files + if [ ! -e "$datadir/mysql/user.frm" ] ; then + rm -rf "$datadir"/* + fi + exit $ret + fi + # In case we're running as root, make sure files are owned properly + chown -R "$myuser:$mygroup" "$datadir" +fi + +exit 0 diff --git a/mariadb-wait-ready b/mariadb-wait-ready new file mode 100644 index 0000000..9e5d3e4 --- /dev/null +++ b/mariadb-wait-ready @@ -0,0 +1,56 @@ +#!/bin/sh + +# This script waits for mysqld to be ready to accept connections +# (which can be many seconds or even minutes after launch, if there's +# a lot of crash-recovery work to do). +# Running this as ExecStartPost is useful so that services declared as +# "After mysqld" won't be started until the database is really ready. + +# Service file passes us the daemon's PID (actually, mysqld_safe's PID) +daemon_pid="$1" + +# extract value of a MySQL option from config files +# Usage: get_mysql_option SECTION VARNAME DEFAULT +# result is returned in $result +# 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` + if [ -z "$result" ]; then + # not found, use default + result="$3" + fi +} + +# Defaults here had better match what mysqld_safe will default to +get_mysql_option mysqld datadir "/var/lib/mysql" +datadir="$result" +get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock" +socketfile="$result" + +# Wait for the server to come up or for the mysqld process to disappear +ret=0 +while /bin/true; do + RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` + mret=$? + if [ $mret -eq 0 ]; then + break + fi + # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected, + # anything else suggests a configuration error + if [ $mret -ne 1 -a $mret -ne 11 ]; then + ret=1 + break + fi + # "Access denied" also means the server is alive + echo "$RESPONSE" | grep -q "Access denied for user" && break + + # Check process still exists + if ! /bin/kill -0 $daemon_pid 2>/dev/null; then + ret=1 + break + fi + sleep 1 +done + +exit $ret diff --git a/mariadb.service b/mariadb.service new file mode 100644 index 0000000..89cbd1a --- /dev/null +++ b/mariadb.service @@ -0,0 +1,48 @@ +# It's not recommended to modify this file in-place, because it will be +# overwritten during package upgrades. If you want to customize, the +# best way is to create a file "/etc/systemd/system/mariadb.service", +# containing +# .include /lib/systemd/system/mariadb.service +# ...make your changes here... +# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf", +# which doesn't need to include ".include" call and which will be parsed +# after the file mariadb.service itself is parsed. +# +# For more info about custom unit files, see systemd.unit(5) or +# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F + +# For example, if you want to increase mysql's open-files-limit to 10000, +# you need to increase systemd's LimitNOFILE setting, so create a file named +# "/etc/systemd/system/mariadb.service.d/limits.conf" containing: +# [Service] +# LimitNOFILE=10000 + +# Note: /usr/lib/... is recommended in the .include line though /lib/... +# still works. +# Don't forget to reload systemd daemon after you change unit configuration: +# root> systemctl --system daemon-reload + +[Unit] +Description=MariaDB database server +After=syslog.target +After=network.target + +[Service] +Type=simple +User=mysql +Group=mysql + +ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n +# Note: we set --basedir to prevent probes that might trigger SELinux alarms, +# per bug #547485 +ExecStart=/usr/bin/mysqld_safe --basedir=/usr +ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID + +# Give a reasonable amount of time for the server to start up/shut down +TimeoutSec=300 + +# Place temp files in a secure directory, not /tmp +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/mariadb.spec b/mariadb.spec index 67a11e0..4b7158b 100644 --- a/mariadb.spec +++ b/mariadb.spec @@ -3,7 +3,7 @@ Name: mariadb Version: 5.5.32 -Release: 11%{?dist} +Release: 12%{?dist} Epoch: 1 Summary: A community developed branch of MySQL @@ -29,6 +29,7 @@ License: GPLv2 with exceptions and LGPLv2 and BSD # the beginning of the transaction and mysqld is enabled again in the end # of the transaction in case this flag file exists. %global mysqld_enabled_flag_file %{_localstatedir}/lib/rpm-state/mysqld_enabled +%global mysqld_running_flag_file %{_localstatedir}/lib/rpm-state/mysqld_running Source0: http://ftp.osuosl.org/pub/mariadb/mariadb-%{version}/kvm-tarbake-jaunty-x86/mariadb-%{version}.tar.gz Source3: my.cnf @@ -38,9 +39,9 @@ Source7: README.mysql-license Source8: libmysql.version Source9: mysql-embedded-check.c Source10: mariadb.tmpfiles.d -Source11: mysqld.service -Source12: mysqld-prepare-db-dir -Source13: mysqld-wait-ready +Source11: mariadb.service +Source12: mariadb-prepare-db-dir +Source13: mariadb-wait-ready Source14: rh-skipped-tests-base.list Source15: rh-skipped-tests-arm.list # Working around perl dependency checking bug in rpm FTTB. Remove later. @@ -63,6 +64,7 @@ Patch14: mariadb-basedir.patch Patch15: mariadb-tmpdir.patch Patch17: mariadb-covscan-signexpr.patch Patch18: mariadb-covscan-stroverflow.patch +Patch19: mariadb-config.patch BuildRequires: perl, readline-devel, openssl-devel BuildRequires: cmake, ncurses-devel, zlib-devel, libaio-devel @@ -264,6 +266,7 @@ MariaDB is a community developed branch of MySQL. %patch15 -p1 %patch17 -p1 %patch18 -p1 +%patch19 -p1 # workaround for upstream bug #56342 rm -f mysql-test/t/ssl_8k_key-master.opt @@ -433,7 +436,11 @@ chmod 0750 $RPM_BUILD_ROOT%{_localstatedir}/log/mariadb touch $RPM_BUILD_ROOT%{_localstatedir}/log/mariadb/mariadb.log ln -s %{_localstatedir}/log/mariadb/mariadb.log $RPM_BUILD_ROOT%{_localstatedir}/log/mysqld.log +# current setting in my.cnf is to use /var/run/mariadb for creating pid file, +# however since my.cnf is not updated by RPM if changed, we need to create mysqld +# as well because users can have od settings in their /etc/my.cnf mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/mysqld +mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/mariadb install -m 0755 -d $RPM_BUILD_ROOT%{_localstatedir}/lib/mysql mkdir -p $RPM_BUILD_ROOT%{_sysconfdir} @@ -442,7 +449,7 @@ install -p -m 0644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/my.cnf # install systemd unit files and scripts for handling server startup mkdir -p ${RPM_BUILD_ROOT}%{_unitdir} install -p -m 644 %{SOURCE11} ${RPM_BUILD_ROOT}%{_unitdir}/ -ln -s mysqld.service ${RPM_BUILD_ROOT}%{_unitdir}/mariadb.service +ln -s mariadb.service ${RPM_BUILD_ROOT}%{_unitdir}/mysqld.service install -p -m 755 %{SOURCE12} ${RPM_BUILD_ROOT}%{_libexecdir}/ install -p -m 755 %{SOURCE13} ${RPM_BUILD_ROOT}%{_libexecdir}/ @@ -530,16 +537,29 @@ if /bin/systemctl is-enabled mysqld.service >/dev/null 2>&1 ; then touch %mysqld_enabled_flag_file >/dev/null 2>&1 || : fi +# Since mysqld.service became a symlink to mariadb.service, turning off +# the running mysqld service doesn't work fine (BZ#1002996). As a work-around +# we explicitly stop mysqld before upgrade and start after it again. +if [ ! -L %{_unitdir}/mysqld.service ] && /bin/systemctl is-active mysqld.service &>/dev/null ; then + touch %mysqld_running_flag_file >/dev/null 2>&1 || : + /bin/systemctl stop mysqld.service >/dev/null 2>&1 || : +fi + %posttrans server -if [ -f %mysqld_enabled_flag_file ]; then - /bin/systemctl enable mysqld.service >/dev/null 2>&1 || : +if [ -f %mysqld_enabled_flag_file ] ; then + /bin/systemctl enable mariadb.service >/dev/null 2>&1 || : rm -f %mysqld_enabled_flag_file >/dev/null 2>&1 || : fi +if [ -f %mysqld_running_flag_file ] ; then + /bin/systemctl start mariadb.service >/dev/null 2>&1 || : + rm -f %mysqld_running_flag_file >/dev/null 2>&1 || : +fi + %post libs -p /sbin/ldconfig %post server -%systemd_post mysqld.service +%systemd_post mariadb.service /bin/chmod 0755 %{_localstatedir}/lib/mysql /bin/touch %{_localstatedir}/log/mariadb/mariadb.log @@ -554,12 +574,12 @@ if [ $1 -eq 0 ] ; then fi %preun server -%systemd_preun mysqld.service +%systemd_preun mariadb.service %postun libs -p /sbin/ldconfig %postun server -%systemd_postun_with_restart mysqld.service +%systemd_postun_with_restart mariadb.service if [ $1 -eq 0 ] ; then %{_sbindir}/update-alternatives --remove mysqlbug %{_libdir}/mysql/mysqlbug fi @@ -727,11 +747,12 @@ fi %{_unitdir}/mysqld.service %{_unitdir}/mariadb.service -%{_libexecdir}/mysqld-prepare-db-dir -%{_libexecdir}/mysqld-wait-ready +%{_libexecdir}/mariadb-prepare-db-dir +%{_libexecdir}/mariadb-wait-ready %{_tmpfilesdir}/%{name}.conf %attr(0755,mysql,mysql) %dir %{_localstatedir}/run/mysqld +%attr(0755,mysql,mysql) %dir %{_localstatedir}/run/mariadb %attr(0755,mysql,mysql) %dir %{_localstatedir}/lib/mysql %attr(0750,mysql,mysql) %dir %{_localstatedir}/log/mariadb %attr(0640,mysql,mysql) %config(noreplace) %verify(not md5 size mtime) %{_localstatedir}/log/mariadb/mariadb.log @@ -767,6 +788,13 @@ fi %{_mandir}/man1/mysql_client_test.1* %changelog +* Mon Sep 2 2013 Honza Horak - 1:5.5.32-12 +- Re-organize my.cnf to include only generic settings + Resolves: #1003115 +- Move pid file location to /var/run/mariadb +- Make mysqld a symlink to mariadb unit file rather than the opposite way + Related: #999589 + * Thu Aug 29 2013 Honza Horak - 1:5.5.32-11 - Move log file into /var/log/mariadb/mariadb.log - Rename logrotate script to mariadb diff --git a/mariadb.tmpfiles.d b/mariadb.tmpfiles.d index 74cd5f8..fbfe4d9 100644 --- a/mariadb.tmpfiles.d +++ b/mariadb.tmpfiles.d @@ -1 +1,2 @@ d /var/run/mysqld 0755 mysql mysql - +d /var/run/mariadb 0755 mysql mysql - diff --git a/my.cnf b/my.cnf index 2a5311b..ac882ac 100644 --- a/my.cnf +++ b/my.cnf @@ -5,13 +5,23 @@ socket=/var/lib/mysql/mysql.sock symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, -# customize your systemd unit file for mysqld according to the +# customize your systemd unit file for mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd -[mysqld_safe] -log-error=/var/log/mariadb/mariadb.log +# Currently, there are mariadb and community-mysql packages in Fedora. +# This particular config file is included in respective RPMs of both of them, +# so the following settings are general and will be also used by both of them. +# Otherwise the RPMs would be in conflict. +# Settings for particular implementations like MariaDB are then +# defined in appropriate sections; for MariaDB server in [mariadb] section in +# /etc/my.cnf.d/server.cnf (part of mariadb-server). +# It doesn't matter that we set these settings only for [mysqld] here, +# because they will be read and used in mysqld_safe as well. +log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid +[mysqld_safe] + # # include all files from the config directory # diff --git a/mysqld-prepare-db-dir b/mysqld-prepare-db-dir deleted file mode 100644 index 8762ab7..0000000 --- a/mysqld-prepare-db-dir +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/sh - -# This script creates the mysql data directory during first service start. -# In subsequent starts, it does nothing much. - -# extract value of a MySQL option from config files -# Usage: get_mysql_option SECTION VARNAME DEFAULT -# result is returned in $result -# 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` - if [ -z "$result" ]; then - # not found, use default - result="$3" - fi -} - -# Defaults here had better match what mysqld_safe will default to -get_mysql_option mysqld datadir "/var/lib/mysql" -datadir="$result" -get_mysql_option mysqld_safe log-error "/var/log/mariadb/mariadb.log" -errlogfile="$result" - -# Absorb configuration settings from the specified systemd service file, -# or the default "mysqld" service if not specified -SERVICE_NAME="$1" -if [ x"$SERVICE_NAME" = x ] -then - SERVICE_NAME=mysqld.service -fi - -myuser=`systemctl show -p User "${SERVICE_NAME}" | - sed 's/^User=//'` -if [ x"$myuser" = x ] -then - myuser=mysql -fi - -mygroup=`systemctl show -p Group "${SERVICE_NAME}" | - sed 's/^Group=//'` -if [ x"$mygroup" = x ] -then - mygroup=mysql -fi - -# Set up the errlogfile with appropriate permissions -touch "$errlogfile" -chown "$myuser:$mygroup" "$errlogfile" -chmod 0640 "$errlogfile" -[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" - -# Make the data directory -if [ ! -d "$datadir/mysql" ] ; then - # First, make sure $datadir is there with correct permissions - # (note: if it's not, and we're not root, this'll fail ...) - if [ ! -e "$datadir" -a ! -h "$datadir" ] - then - mkdir -p "$datadir" || exit 1 - fi - chown "$myuser:$mygroup" "$datadir" - chmod 0755 "$datadir" - [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir" - - # Now create the database - echo "Initializing MySQL database" - /usr/bin/mysql_install_db --datadir="$datadir" --user="$myuser" - ret=$? - if [ $ret -ne 0 ] ; then - echo "Initialization of MySQL database failed." >&2 - echo "Perhaps /etc/my.cnf is misconfigured." >&2 - # Clean up any partially-created database files - if [ ! -e "$datadir/mysql/user.frm" ] ; then - rm -rf "$datadir"/* - fi - exit $ret - fi - # In case we're running as root, make sure files are owned properly - chown -R "$myuser:$mygroup" "$datadir" -fi - -exit 0 diff --git a/mysqld-wait-ready b/mysqld-wait-ready deleted file mode 100644 index 9e5d3e4..0000000 --- a/mysqld-wait-ready +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -# This script waits for mysqld to be ready to accept connections -# (which can be many seconds or even minutes after launch, if there's -# a lot of crash-recovery work to do). -# Running this as ExecStartPost is useful so that services declared as -# "After mysqld" won't be started until the database is really ready. - -# Service file passes us the daemon's PID (actually, mysqld_safe's PID) -daemon_pid="$1" - -# extract value of a MySQL option from config files -# Usage: get_mysql_option SECTION VARNAME DEFAULT -# result is returned in $result -# 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` - if [ -z "$result" ]; then - # not found, use default - result="$3" - fi -} - -# Defaults here had better match what mysqld_safe will default to -get_mysql_option mysqld datadir "/var/lib/mysql" -datadir="$result" -get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock" -socketfile="$result" - -# Wait for the server to come up or for the mysqld process to disappear -ret=0 -while /bin/true; do - RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` - mret=$? - if [ $mret -eq 0 ]; then - break - fi - # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected, - # anything else suggests a configuration error - if [ $mret -ne 1 -a $mret -ne 11 ]; then - ret=1 - break - fi - # "Access denied" also means the server is alive - echo "$RESPONSE" | grep -q "Access denied for user" && break - - # Check process still exists - if ! /bin/kill -0 $daemon_pid 2>/dev/null; then - ret=1 - break - fi - sleep 1 -done - -exit $ret diff --git a/mysqld.service b/mysqld.service deleted file mode 100644 index ceb26e2..0000000 --- a/mysqld.service +++ /dev/null @@ -1,48 +0,0 @@ -# It's not recommended to modify this file in-place, because it will be -# overwritten during package upgrades. If you want to customize, the -# best way is to create a file "/etc/systemd/system/mysqld.service", -# containing -# .include /lib/systemd/system/mysqld.service -# ...make your changes here... -# or create a file "/etc/systemd/system/mysqld.service.d/foo.conf", -# which doesn't need to include ".include" call and which will be parsed -# after the file mysqld.service itself is parsed. -# -# For more info about custom unit files, see systemd.unit(5) or -# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F - -# For example, if you want to increase mysql's open-files-limit to 10000, -# you need to increase systemd's LimitNOFILE setting, so create a file named -# "/etc/systemd/system/mysqld.service.d/limits.conf" containing: -# [Service] -# LimitNOFILE=10000 - -# Note: /usr/lib/... is recommended in the .include line though /lib/... -# still works. -# Don't forget to reload systemd daemon after you change unit configuration: -# root> systemctl --system daemon-reload - -[Unit] -Description=MariaDB database server -After=syslog.target -After=network.target - -[Service] -Type=simple -User=mysql -Group=mysql - -ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n -# Note: we set --basedir to prevent probes that might trigger SELinux alarms, -# per bug #547485 -ExecStart=/usr/bin/mysqld_safe --basedir=/usr -ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID - -# Give a reasonable amount of time for the server to start up/shut down -TimeoutSec=300 - -# Place temp files in a secure directory, not /tmp -PrivateTmp=true - -[Install] -WantedBy=multi-user.target