~ruther/guix-local

be39b5dee51395aa8acd29d17bc027dba1752443 — Benjamin Chabanne 5 months ago ef42ecb
services: log-rotation: Allow to pass procedure as compression method.

    * gnu/services/admin.scm (log-rotation-configuration): Change
    validation method and accept gexp procedure.

Change-Id: I67cd5051a05d211349ecbc66ee3a55ab5b1a5971
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2 files changed, 39 insertions(+), 28 deletions(-)

M doc/guix.texi
M gnu/services/admin.scm
M doc/guix.texi => doc/guix.texi +6 -4
@@ 21556,10 21556,10 @@ be a @code{log-rotation-configuration} record, as discussed below.
Available @code{log-rotation-configuration} fields are:

@table @asis
@item @code{provision} (default: @code{'(log-rotation)}) (type: list-of-symbols)
@item @code{provision} (default: @code{(log-rotation)}) (type: list-of-symbols)
The name(s) of the log rotation Shepherd service.

@item @code{requirement} (default: @code{'(user-processes)}) (type: list-of-symbols)
@item @code{requirement} (default: @code{(user-processes)}) (type: list-of-symbols)
Dependencies of the log rotation Shepherd service.

@item @code{calendar-event} (type: gexp)


@@ 21570,9 21570,11 @@ on calendar events.
@item @code{external-log-files} (default: @code{()}) (type: list-of-strings)
List of file names, external log files that should also be rotated.

@item @code{compression} (default: @code{zstd}) (type: symbol)
@item @code{compression} (default: @code{zstd}) (type: gexp-or-symbol)
The compression method used for rotated log files, one of @code{'none},
@code{'gzip}, and @code{'zstd}.
@code{'gzip}, and @code{'zstd}.  Alternatively, it can be a gexp that
evaluates to a procedure; that procedure gets called with the file to be
rotated.

@item @code{expiry} (type: gexp-or-integer)
Age in seconds after which a log file is deleted.

M gnu/services/admin.scm => gnu/services/admin.scm +33 -24
@@ 123,6 123,9 @@
(define (gexp-or-integer? x)
  (or (gexp? x) (integer? x)))

(define (gexp-or-symbol? x)
  (or (gexp? x) (symbol? x)))

(define-configuration log-rotation-configuration
  (provision
   (list-of-symbols '(log-rotation))


@@ 144,9 147,10 @@ calendar events."
rotated."
   empty-serializer)
  (compression
   (symbol 'zstd)
   "The compression method used for rotated log files, one of
@code{'none}, @code{'gzip}, and @code{'zstd}."
   (gexp-or-symbol 'zstd)
   "The compression method used for rotated log files, one of @code{'none},
@code{'gzip}, and @code{'zstd}. Alternatively, it can be a gexp that evaluates
to a procedure; that procedure gets called with the file to be rotated."
   empty-serializer)
  (expiry
   (gexp-or-integer #~(%default-log-expiry))


@@ 158,27 162,32 @@ rotated."
   empty-serializer))

(define (log-rotation-shepherd-services config)
  (list (shepherd-service
         (provision (log-rotation-configuration-provision config))
         (requirement (log-rotation-configuration-requirement config))
         (modules '((shepherd service timer)      ;for 'calendar-event'
                    (shepherd service log-rotation)))
         (free-form #~(log-rotation-service
                       #$(log-rotation-configuration-calendar-event config)
                       #:provision
                       '#$(log-rotation-configuration-provision config)
                       #:requirement
                       '#$(log-rotation-configuration-requirement config)
                       #:external-log-files
                       '#$(log-rotation-configuration-external-log-files
                           config)
                       #:compression
                       '#$(log-rotation-configuration-compression config)
                       #:expiry
                       #$(log-rotation-configuration-expiry config)
                       #:rotation-size-threshold
                       #$(log-rotation-configuration-size-threshold
                          config))))))
  (let* ((compression-raw (log-rotation-configuration-compression config))
         (compression
           (if (symbol? compression-raw)
             #~'#$compression-raw
             compression-raw)))
    (list (shepherd-service
           (provision (log-rotation-configuration-provision config))
           (requirement (log-rotation-configuration-requirement config))
           (modules '((shepherd service timer)      ;for 'calendar-event'
                      (shepherd service log-rotation)))
           (free-form #~(log-rotation-service
                         #$(log-rotation-configuration-calendar-event config)
                         #:provision
                         '#$(log-rotation-configuration-provision config)
                         #:requirement
                         '#$(log-rotation-configuration-requirement config)
                         #:external-log-files
                         '#$(log-rotation-configuration-external-log-files
                             config)
                         #:compression
                         #$compression
                         #:expiry
                         #$(log-rotation-configuration-expiry config)
                         #:rotation-size-threshold
                         #$(log-rotation-configuration-size-threshold
                            config)))))))

(define log-rotation-service-type
  (service-type