Skip to content

Commit 6bf998e

Browse files
authored
Merge pull request #160 from linuxserver/add-logrotate
Add logrotate
2 parents a173c33 + 4fd4e37 commit 6bf998e

File tree

14 files changed

+90
-30
lines changed

14 files changed

+90
-30
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/config/log/mysql/*.log {
2+
firstaction
3+
/usr/bin/mariadb-admin -uroot --local version >/dev/null 2>&1
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 -uroot --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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [[ ! -d "${DATADIR}/mysql" ]]; then
3030

3131
# set basic sql command
3232
cat >"${tempSqlFile}" <<-EOSQL
33-
DELETE FROM mysql.user WHERE user <> 'mariadb.sys';
33+
DELETE FROM mysql.user WHERE user <> 'mariadb.sys' AND user <> 'root';
3434
EOSQL
3535

3636
if [[ "${#MYSQL_ROOT_PASSWORD}" -lt "4" ]]; then
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
# check logrotate permissions
5+
if mariadb-admin -uroot --local version >/dev/null 2>&1; then
6+
echo "Logrotate is enabled"
7+
else
8+
cat <<-EOFPASS
9+
10+
11+
12+
#####################################################################################
13+
# #
14+
# Logrotate Instructions #
15+
# #
16+
# Add the following to /config/custom.cnf under [mysqld]: #
17+
# log_error = /config/log/mysql/mariadb-error.log #
18+
# #
19+
# Login to the SQL shell inside the container using: #
20+
# mariadb -uroot -p<PASSWORD> #
21+
# And run the following command: #
22+
# GRANT ALL ON *.* TO root@localhost IDENTIFIED VIA unix_socket WITH GRANT OPTION ; #
23+
# #
24+
# Restart the container to apply the changes. #
25+
# #
26+
# You can read more about root@localhost permissions here: #
27+
# https://mariadb.com/kb/en/authentication-from-mariadb-10-4/ #
28+
# #
29+
#####################################################################################
30+
31+
32+
33+
EOFPASS
34+
fi
35+
36+
# check for upgrades
37+
if [[ "${#MYSQL_ROOT_PASSWORD}" -gt "3" ]]; then
38+
# display a message about upgrading database if needed
39+
if mariadb-upgrade -u root -p"${MYSQL_ROOT_PASSWORD}" --check-if-upgrade-is-needed >/dev/null 2>&1; then
40+
cat <<-EOF
41+
42+
43+
44+
#################################################################
45+
# #
46+
# An upgrade is required on your databases. #
47+
# #
48+
# Stop any services that are accessing databases #
49+
# in this container, and then run the command #
50+
# #
51+
# mariadb-upgrade -u root #
52+
# #
53+
#################################################################
54+
55+
56+
57+
EOF
58+
sleep 5s
59+
fi
60+
fi

0 commit comments

Comments
 (0)