diff options
author | Otto Kekäläinen <otto@kekalainen.net> | 2022-05-04 21:42:38 -0700 |
---|---|---|
committer | Daniel Black <daniel@mariadb.org> | 2022-10-27 10:28:14 +1100 |
commit | fd0dcad676e7b8665f5363d97849a20cbb712933 (patch) | |
tree | 98675748fa416ef56ff101c863dd0069907ee63d /support-files | |
parent | dc3be2426856a3adbdc7649f53cb080b755ef328 (diff) | |
download | mariadb-git-fd0dcad676e7b8665f5363d97849a20cbb712933.tar.gz |
MDEV-22659: Create one single unified and optimal logrotate config
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.11 branch onward we use now the
'mariadb' name, and use 'logrotate' to match the actual name of the
utility.
Also automatically disable deprecated /etc/logrotate.d/mysql-server
file on deb upgrades.
Reviewer: Daniel Black
Reviewer edits made:
* Added 'su mysql mysql' to the logrotate this is more RPM friendly.
This is commented on Debian
* /var/log/mysql is the path on SuSe based distributions
Diffstat (limited to 'support-files')
-rw-r--r-- | support-files/CMakeLists.txt | 20 | ||||
-rw-r--r-- | support-files/mariadb.logrotate.sh | 59 | ||||
-rw-r--r-- | support-files/mysql-log-rotate.sh | 38 |
3 files changed, 76 insertions, 41 deletions
diff --git a/support-files/CMakeLists.txt b/support-files/CMakeLists.txt index 9623440f110..26091e472a3 100644 --- a/support-files/CMakeLists.txt +++ b/support-files/CMakeLists.txt @@ -32,6 +32,19 @@ ELSE() SET(MYSQLD_GROUP "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(su_user "su mysql mysql") + IF(RPM MATCHES "(suse|sles)") + SET(logdir "/var/log/mysql") + ELSEIF(RPM) + SET(logdir "/var/log/mariadb") + ELSE() + SET(logdir "/var/log/mysql") + ENDIF() + IF(DEB) + SET(su_user "#su mysql mysql") + ENDIF() ENDIF() # XXX: shouldn't we just have variables for all this stuff and centralise @@ -51,7 +64,7 @@ ENDIF() IF(UNIX AND NOT WITHOUT_SERVER) SET(prefix ${CMAKE_INSTALL_PREFIX}) - FOREACH(script mysqld_multi.server mysql-log-rotate binary-configure wsrep_notify mini-benchmark) + FOREACH(script mysqld_multi.server mariadb.logrotate binary-configure wsrep_notify mini-benchmark) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh ${CMAKE_CURRENT_BINARY_DIR}/${script} @ONLY ) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script} @@ -199,8 +212,9 @@ IF(UNIX AND NOT WITHOUT_SERVER) 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 diff --git a/support-files/mariadb.logrotate.sh b/support-files/mariadb.logrotate.sh new file mode 100644 index 00000000000..811b274778f --- /dev/null +++ b/support-files/mariadb.logrotate.sh @@ -0,0 +1,59 @@ +# 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 @localstatedir@/mariadb.log @logdir@/*.log { + + # Depends on a mysql@localhost unix_socket authenticated user with RELOAD privilege + @su_user@ + + # 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 'mysql' + # (or root on Debian) account used everywhere since MariaDB 10.4. + postrotate + if test -r /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 +} diff --git a/support-files/mysql-log-rotate.sh b/support-files/mysql-log-rotate.sh deleted file mode 100644 index c89aa6e0b99..00000000000 --- a/support-files/mysql-log-rotate.sh +++ /dev/null @@ -1,38 +0,0 @@ -# This logname can be set in /etc/my.cnf -# by setting the variable "log-error" -# in the [mysqld] section as follows: -# -# [mysqld] -# log-error=@localstatedir@/mysqld.log -# -# If the root user has a password you have to create a -# /root/.my.cnf configuration file with the following -# content: -# -# [mysqladmin] -# password = <secret> -# user= root -# -# where "<secret>" is the password. -# -# ATTENTION: This /root/.my.cnf should be readable ONLY -# for root ! - -@localstatedir@/mysqld.log { - # create 600 mysql mysql - su mysql mysql - notifempty - daily - rotate 3 - missingok - compress - postrotate - # just if mariadbd is really running - if test -x @bindir@/mysqladmin && \ - @bindir@/mysqladmin ping &>/dev/null - then - @bindir@/mysqladmin --local flush-error-log \ - flush-engine-log flush-general-log flush-slow-log - fi - endscript -} |