Skip to content

Commit bb28a9d

Browse files
committed
Add logrotate
1 parent fb00241 commit bb28a9d

File tree

14 files changed

+84
-29
lines changed

14 files changed

+84
-29
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN \
2121
fi && \
2222
apk add --no-cache \
2323
gnupg \
24+
logrotate \
2425
mariadb==${MARIADB_VERSION} \
2526
mariadb-backup==${MARIADB_VERSION} \
2627
mariadb-client==${MARIADB_VERSION} \

Dockerfile.aarch64

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN \
2121
fi && \
2222
apk add --no-cache \
2323
gnupg \
24+
logrotate \
2425
mariadb==${MARIADB_VERSION} \
2526
mariadb-backup==${MARIADB_VERSION} \
2627
mariadb-client==${MARIADB_VERSION} \

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
366366

367367
## Versions
368368

369+
* **11.01.25:** - Add log rotation, follow the instructions in the container log.
369370
* **06.01.25:** - Rebase to Alpine 3.21.
370371
* **31.05.24:** - Rebase to Alpine 3.20.
371372
* **23.12.23:** - Rebase to Alpine 3.19.

readme-vars.yml

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ init_diagram: |
142142
"mariadb:latest" <- Base Images
143143
# changelog
144144
changelogs:
145+
- {date: "11.01.25:", desc: "Add log rotation, follow the instructions in the container log."}
145146
- {date: "06.01.25:", desc: "Rebase to Alpine 3.21."}
146147
- {date: "31.05.24:", desc: "Rebase to Alpine 3.20."}
147148
- {date: "23.12.23:", desc: "Rebase to Alpine 3.19."}

root/defaults/custom.cnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ console = 1
102102
#
103103
log_warnings = 2
104104
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf
105-
#log_error = /config/log/mysql/mysql.log
105+
log_error = /config/log/mysql/mariadb-error.log
106106
#
107107
# Enable the slow query log to see queries with especially long duration
108108
slow_query_log = 1

root/etc/logrotate.d/mariadb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/config/log/mysql/*.log /config/log/mysql/*.err {
2+
firstaction
3+
/usr/bin/mariadb-admin --local version 2> /dev/null
4+
endscript
5+
su abc abc
6+
missingok
7+
create 660 abc abc
8+
notifempty
9+
daily
10+
minsize 1M
11+
maxsize 100M
12+
rotate 30
13+
dateext
14+
dateformat .%Y-%m-%d-%H-%M-%S
15+
compress
16+
delaycompress
17+
sharedscripts
18+
olddir archive/
19+
createolddir 770 abc abc
20+
postrotate
21+
/usr/bin/mariadb-admin --local flush-error-log flush-engine-log flush-general-log flush-slow-log
22+
endscript
23+
}

root/etc/s6-overlay/s6-rc.d/init-mariadb-initdb/run

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ EOM
5757
cat >>"${tempSqlFile}" <<-EONEWSQL
5858
$MYSQL_PASS
5959
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
60+
DROP USER 'root'@'localhost';
61+
GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION ;
6062
DROP DATABASE IF EXISTS test ;
6163
$MYSQL_DB_SETUP
6264
EONEWSQL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
# check logrotate permissions
5+
if mariadb-admin --local version 2> /dev/null; then
6+
echo "Logrotate is enabled"
7+
else
8+
cat <<-EOFPASS
9+
10+
11+
12+
#####################################################################################
13+
# #
14+
# Logrotate requires the following permission: #
15+
# GRANT ALL ON *.* TO root@localhost IDENTIFIED VIA unix_socket WITH GRANT OPTION ; #
16+
# You can grant it via: #
17+
# mariadb -uroot -p<PASSWORD> #
18+
# #
19+
# You can read more about it here: #
20+
# https://mariadb.com/kb/en/authentication-from-mariadb-10-4/ #
21+
# #
22+
#####################################################################################
23+
24+
25+
26+
EOFPASS
27+
fi
28+
29+
# check for upgrades
30+
if [[ "${#MYSQL_ROOT_PASSWORD}" -gt "3" ]]; then
31+
# display a message about upgrading database if needed
32+
if mariadb-upgrade -u root -p"${MYSQL_ROOT_PASSWORD}" --check-if-upgrade-is-needed >/dev/null 2>&1; then
33+
cat <<-EOF
34+
35+
36+
37+
#################################################################
38+
# #
39+
# An upgrade is required on your databases. #
40+
# #
41+
# Stop any services that are accessing databases #
42+
# in this container, and then run the command #
43+
# #
44+
# mariadb-upgrade -u root #
45+
# #
46+
#################################################################
47+
48+
49+
50+
EOF
51+
sleep 5s
52+
fi
53+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mariadb-poststart/run

root/etc/s6-overlay/s6-rc.d/init-mariadb-upgrade/run

-27
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-mariadb-upgrade/up

-1
This file was deleted.

0 commit comments

Comments
 (0)