civodul pushed a commit to branch main in repository shepherd. commit b613ab0215a77aa0e6c43c2a516af7cee31c8567 Author: Ludovic Courtès <l...@gnu.org> AuthorDate: Sun Mar 30 12:49:39 2025 +0200
log-rotation: Do not compress already-compressed log files. * modules/shepherd/service/log-rotation.scm (file-extension) (compressed-file?): New procedures. (rotate-file): Do not call ‘compress-file’ when FILE matches ‘compressed-file?’. * NEWS: Update. --- NEWS | 5 +++++ modules/shepherd/service/log-rotation.scm | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 246f94f..1931874 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,11 @@ It used to be that, when trying to start a one-shot service that was already starting, ‘herd start’ would wrongfully report failure to start. This is no longer the case. +** ‘log-rotation’ does not compressed already-compressed log files + +Programs such as nginx can compress log files as they write them. The +‘log-rotation’ service no longer re-compresses such log files. + * Changes in 1.0.3 ** ‘spawn-command’ now honors #:log-file diff --git a/modules/shepherd/service/log-rotation.scm b/modules/shepherd/service/log-rotation.scm index 5ad0021..0b9374d 100644 --- a/modules/shepherd/service/log-rotation.scm +++ b/modules/shepherd/service/log-rotation.scm @@ -46,6 +46,15 @@ ;; Compressed file extensions. '("gz" "bz2" "lz" "lzma" "xz" "zst")) +(define (file-extension file) + "Return the extension of @var{file} or @code{#f} if there is none." + (let ((dot (string-rindex file #\.))) + (and dot (string-drop file (+ 1 dot))))) + +(define (compressed-file? file) + "Return true if @var{file} denotes a compressed file." + (->bool (member (file-extension file) %compression-extensions))) + (define (next-rotated-file-name reference file) "Return the file name @var{file} should be renamed to and its rotation number (an integer). Return #f and #f if @var{file} is not rotated from the @@ -151,7 +160,8 @@ called with @var{file}." (let* ((next (string-append file ".1")) (rotated? (rotate-current file next))) (when rotated? - (compress-file compression next) + (unless (compressed-file? file) + (compress-file compression next)) (local-output (l10n "Rotated '~a'.") file)))) (else (local-output