Skip to content

Commit

Permalink
MDEV-22659: Create one single unified and optimal logrotate config
Browse files Browse the repository at this point in the history
Replace mysql-log-rotate.sh and debian/...mysql-server.logrotate with one
new unified and well documented version.

Name is mariadb.logrotate.in as in 10.5 branch we use now the 'mariadb'
name, and use 'logrotate' to match the actual name of the utility, and
use '.in' instead of '.sh' as this is not a shell script but a template
file.

Also automatically disable deprecated /etc/logrotate.d/mysql-server
file on deb upgrades.
  • Loading branch information
ottok committed May 8, 2021
1 parent 35977e8 commit f6c3ad1
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ support-files/my-innodb-heavy-4G.cnf
support-files/my-large.cnf
support-files/my-medium.cnf
support-files/my-small.cnf
support-files/mysql-log-rotate
support-files/mariadb.logrotate
support-files/mysql.10.0.11.spec
support-files/mysql.server
support-files/mysql.service
Expand Down
1 change: 1 addition & 0 deletions debian/mariadb-server-10.5.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ debian/additions/mariadb.conf.d/50-mysqld_safe.cnf etc/mysql/mariadb.conf.d
debian/additions/mariadb.conf.d/50-server.cnf etc/mysql/mariadb.conf.d
debian/additions/source_mariadb-10.5.py usr/share/apport/package-hooks
etc/apparmor.d/usr.sbin.mariadbd
etc/logrotate.d/mariadb
etc/security/user_map.conf
lib/*/security/pam_user_map.so
lib/systemd/system/mariadb@bootstrap.service.d/use_galera_new_cluster.conf
Expand Down
20 changes: 0 additions & 20 deletions debian/mariadb-server-10.5.mysql-server.logrotate

This file was deleted.

7 changes: 7 additions & 0 deletions debian/mariadb-server-10.5.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ EOF
fi
fi

# The introduction of /etc/logrotate.d/mariadb has made the old config
# obsolete and it needs to be disabled to prevent logrotate running twice.
if [ -f /etc/logrotate.d/mysql-server ]
then
mv -vf /etc/logrotate.d/mysql-server /etc/logrotate.d/mysql-server.dpkg-bak
fi

# @TODO: Remove once buildbot.askmonty.org has been updated not to expect this file
mkdir -p /etc/systemd/system/mariadb.service.d/
# Note that file cannot be empty, otherwise systemd version in Ubuntu Bionic
Expand Down
1 change: 0 additions & 1 deletion debian/not-installed
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ usr/share/mysql/binary-configure
usr/share/mysql/magic
usr/share/mysql/maria_add_gis_sp.sql
usr/share/mysql/mysqld_multi.server
usr/share/mysql/mysql-log-rotate
usr/share/mysql/mysql.server
usr/share/mysql/mysql-test/mtr # Already created by mariadb-test.links
usr/share/mysql/mysql-test/mysql-test-run # Already created by mariadb-test.links
Expand Down
3 changes: 0 additions & 3 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ endif
# Move test plugins that are only needed by the client to the libmariadb path
mv -v $(TMP)/usr/lib/mysql/plugin/qa_auth_client.so $(TMP)/usr/lib/$(DEB_HOST_MULTIARCH)/libmariadb3/plugin/

override_dh_installlogrotate-arch:
dh_installlogrotate --name mysql-server

override_dh_systemd_enable:
dh_systemd_enable --name=mariadb
dh_systemd_enable --no-enable --name=mariadb@
Expand Down
24 changes: 15 additions & 9 deletions support-files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright (c) 2006, 2016, Oracle and/or its affiliates.
# Copyright (c) 2012, 2017, MariaDB
#
#
# 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
# the Free Software Foundation; version 2 of the License.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
Expand All @@ -31,6 +31,9 @@ ELSE()
SET(MYSQLD_USER "mysql")
SET(ini_file_extension "cnf")
SET(HOSTNAME "uname -n")

# Define directly here, as cmake/install_layout.cmake has no LOGDIR to be inherited
SET(logdir "/var/log/mysql")
ENDIF()

# XXX: shouldn't we just have variables for all this stuff and centralise
Expand All @@ -50,9 +53,11 @@ ENDIF()

IF(UNIX)
SET(prefix ${CMAKE_INSTALL_PREFIX})
FOREACH(script mysqld_multi.server mysql-log-rotate binary-configure wsrep_notify)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh
FOREACH(script mysqld_multi.server binary-configure wsrep_notify)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh
${CMAKE_CURRENT_BINARY_DIR}/${script} @ONLY )
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mariadb.logrotate.in
${CMAKE_CURRENT_BINARY_DIR}/mariadb.logrotate @ONLY )
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script}
DESTINATION ${inst_location} COMPONENT Server_Scripts)
ENDFOREACH()
Expand Down Expand Up @@ -94,7 +99,7 @@ IF(UNIX)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mariadb.pc DESTINATION ${INSTALL_LIBDIR}/pkgconfig COMPONENT Development)

INSTALL(FILES mysql.m4 DESTINATION ${INSTALL_SHAREDIR}/aclocal COMPONENT Development)

SET(bindir ${INSTALL_BINDIRABS})
SET(sbindir ${INSTALL_SBINDIRABS})
SET(scriptdir ${INSTALL_SCRIPTDIRABS})
Expand All @@ -112,7 +117,7 @@ IF(UNIX)
ELSE()
SET(sysconf2dir "${sysconfdir}/mysql")
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql.server.sh
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql.server.sh
${CMAKE_CURRENT_BINARY_DIR}/mysql.server @ONLY)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mysql.server
DESTINATION ${inst_location} COMPONENT SupportFiles)
Expand Down Expand Up @@ -181,8 +186,9 @@ IF(UNIX)
ENDIF()

IF (INSTALL_SYSCONFDIR)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mysql-log-rotate DESTINATION ${INSTALL_SYSCONFDIR}/logrotate.d
RENAME mysql COMPONENT SupportFiles)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mariadb.logrotate
DESTINATION ${INSTALL_SYSCONFDIR}/logrotate.d
RENAME mariadb COMPONENT SupportFiles)
IF(NOT HAVE_SYSTEMD)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mysql.server
DESTINATION ${INSTALL_SYSCONFDIR}/init.d
Expand Down
56 changes: 56 additions & 0 deletions support-files/mariadb.logrotate.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This is the MariaDB configuration for the logrotate utility
#
# Note that on most Linux systems logs are written to journald, which has its
# own rotation scheme.
#
# Read https://mariadb.com/kb/en/error-log/ to learn more about logging and
# https://mariadb.com/kb/en/rotating-logs-on-unix-and-linux/ about rotating logs.

@localstatedir@/mysqld.log @logdir@/mysql.log @localstatedir@/mariadb.log @logdir@/mysql-slow.log @logdir@/mariadb-slow.log @logdir@/error.log {

# If any of the files listed above is missing, skip them silently without
# emitting any errors
missingok

# If file exists but is empty, don't rotate it
notifempty

# Run monthly
monthly

# Keep 6 months of logs
rotate 6

# If file is growing too big, rotate immediately
maxsize 500M

# If file size is too small, don't rotate at all
minsize 50M

# Compress logs, as they are text and compression will save a lot of disk space
compress

# Don't compress the log immediately to avoid errors about "file size changed while zipping"
delaycompress

# Don't run the postrotate script for each file configured in this file, but
# run it only once if one or more files were rotated
sharedscripts

# After each rotation, run this custom script to flush the logs. Note that
# this assumes that the mariadb-admin command has database access, which it
# has thanks to the default use of Unix socket authentication for the 'root'
# account used everywhere since MariaDB 10.4.
postrotate
if test -x /etc/mysql/debian.cnf
then
EXTRAPARAM='--defaults-file=/etc/mysql/debian.cnf'
fi

if test -x @bindir@/mariadb-admin
then
@bindir@/mariadb-admin $EXTRAPARAM --local flush-error-log \
flush-engine-log flush-general-log flush-slow-log
fi
endscript
}
37 changes: 0 additions & 37 deletions support-files/mysql-log-rotate.sh

This file was deleted.

0 comments on commit f6c3ad1

Please sign in to comment.