From 6e76f8e6cc8195b3cfc32b4d7f13f8f62db81785 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Mon, 9 Oct 2023 20:08:37 +0300 Subject: [PATCH] fix: logrotate for dragonfly logs (#1972) The new logrotate settings assume that dragonfly closes a log file once it grows to large. It never rotates file that is currently open for writing. Specifically logrotate: 1. rotate only log files 2. skip those that are currently open by as process. 3. compresses using zstd which is more cpu efficient than gzip 4. does not truncate/create old files as 0-sized blobs - just renames them Fixes #1935 Signed-off-by: Roman Gershman --- src/server/dfly_main.cc | 3 +++ tools/packaging/debian/control | 2 +- tools/packaging/debian/dragonfly.conf | 1 + tools/packaging/debian/dragonfly.logrotate | 25 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/server/dfly_main.cc b/src/server/dfly_main.cc index 87296bf2b..897fe5ad8 100644 --- a/src/server/dfly_main.cc +++ b/src/server/dfly_main.cc @@ -787,8 +787,11 @@ Usage: dragonfly [FLAGS] }; absl::SetFlagsUsageConfig(config); + google::InitGoogleLogging(argv[0]); + google::SetLogFilenameExtension(".log"); MainInitGuard guard(&argc, &argv); + ParseFlagsFromEnv(); PrintBasicUsageInfo(); diff --git a/tools/packaging/debian/control b/tools/packaging/debian/control index 2a4e2a6bf..f62ae3f15 100644 --- a/tools/packaging/debian/control +++ b/tools/packaging/debian/control @@ -7,6 +7,6 @@ Vcs-Git: https://github.com/dragonflydb/dragonfly Package: dragonfly Architecture: amd64 arm64 -Depends: libc6, openssl, adduser +Depends: libc6, openssl, adduser, zstd Homepage: https://dragonflydb.io Description: A fast in-memory store that is fully compatible with Redis™* and Memcached. diff --git a/tools/packaging/debian/dragonfly.conf b/tools/packaging/debian/dragonfly.conf index 564fe9507..9226ee696 100644 --- a/tools/packaging/debian/dragonfly.conf +++ b/tools/packaging/debian/dragonfly.conf @@ -1,4 +1,5 @@ --pidfile=/var/run/dragonfly/dragonfly.pid --log_dir=/var/log/dragonfly --dir=/var/lib/dragonfly +--max_log_size=20 --version_check=true diff --git a/tools/packaging/debian/dragonfly.logrotate b/tools/packaging/debian/dragonfly.logrotate index 84214927e..2047f613e 100644 --- a/tools/packaging/debian/dragonfly.logrotate +++ b/tools/packaging/debian/dragonfly.logrotate @@ -1,7 +1,26 @@ -/var/log/dragonfly/dragonfly* { - weekly +# installed by debhelper by convention into /etc/logrotate.d/ + +/var/log/dragonfly/dragonfly*.log { + daily missingok - rotate 12 + compress + compresscmd zstd + uncompresscmd unzstd + compressext .zst notifempty + +# do not create an empty file after the rotation. + nocreate + prerotate + if lsof -t $1 > /dev/null; then + # file is open. Skipping rotation." + exit 1 + fi + endscript + +# Possible hook to upload rotated logs to cloud storage. + postrotate + echo "TBD: POSTROTATE" + endscript }