summaryrefslogtreecommitdiffstats
path: root/debian/patches/1556.patch
blob: adc7a6b0e032f760bff8f519dc12bd18e4d8e549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
Forwarded: https://github.com/MariaDB/server/pull/1556
From 3cf95de573a6b10e68df2efc1f8cf2f42fdd2d68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= <otto@kekalainen.net>
Date: Wed, 30 Sep 2020 20:01:35 +0300
Subject: [PATCH] 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.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.

--- a/.gitignore
+++ b/.gitignore
@@ -275,7 +275,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
--- a/support-files/CMakeLists.txt
+++ b/support-files/CMakeLists.txt
@@ -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
@@ -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
@@ -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()
@@ -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})
@@ -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)
@@ -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
--- /dev/null
+++ b/support-files/mariadb.logrotate.in
@@ -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
+}
--- a/support-files/mysql-log-rotate.sh
+++ /dev/null
@@ -1,37 +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
-        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
-}