From: "Ludovic Courtès" <ludo@gnu.org>
To: 74860@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
"Ludovic Courtès" <ludo@gnu.org>,
"Maxim Cournoyer" <maxim.cournoyer@gmail.com>
Subject: [bug#74860] [PATCH v2 03/12] services: Add ‘log-rotation-service-type’.
Date: Wed, 8 Jan 2025 18:41:47 +0100 [thread overview]
Message-ID: <3c927596ee81d985d925c8b72bf4a3f33336b457.1736357737.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1736357737.git.ludo@gnu.org>
* gnu/services/admin.scm (%default-log-rotation-calendar-event): New
variable.
(<log-rotation-configuration>): New record type.
(log-rotation-shepherd-services): New procedure.
(log-rotation-service-type): New variable.
Change-Id: I4400035f3b6065ec147ac932110b690120d739c2
---
doc/guix.texi | 82 +++++++++++++++++++++++++++--
gnu/services/admin.scm | 116 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 187 insertions(+), 11 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index caebe3b03c..f521a2d2ad 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -394,7 +394,7 @@ Top
* Base Services:: Essential system services.
* Scheduled Job Execution:: The mcron service.
-* Log Rotation:: The rottlog service.
+* Log Rotation:: Archiving and deleting old logs.
* Networking Setup:: Setting up network interfaces.
* Networking Services:: Firewall, SSH daemon, etc.
* Unattended Upgrades:: Automated system upgrades.
@@ -19229,7 +19229,7 @@ Services
@menu
* Base Services:: Essential system services.
* Scheduled Job Execution:: The mcron service.
-* Log Rotation:: The rottlog service.
+* Log Rotation:: Archiving and deleting old logs.
* Networking Setup:: Setting up network interfaces.
* Networking Services:: Firewall, SSH daemon, etc.
* Unattended Upgrades:: Automated system upgrades.
@@ -20872,8 +20872,82 @@ Log Rotation
Log files such as those found in @file{/var/log} tend to grow endlessly,
so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
their contents in separate files, possibly compressed. The @code{(gnu
-services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
-log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
+services admin)} module provides an interface to the log rotation
+service provided by the Shepherd (@pxref{Log Rotation,,, shepherd, The
+GNU Shepherd Manual}).
+
+This log rotation service is made available through
+@code{log-rotation-service-type}, which takes a
+@code{log-rotation-configuration} record has its value. By default,
+this provides @code{log-rotation}, a Shepherd ``timed service'' that
+runs periodically---once a week by default. It automatically knows
+about the log files produced by Shepherd services and can be taught
+about external log files. You can inspect the service and see when it's
+going to run the usual way:
+
+@example
+$ sudo herd status log-rotation
+Status of log-rotation:
+ It is running since Mon 09 Dec 2024 03:27:47 PM CET (2 days ago).
+ @dots{}
+
+Upcoming timer alarms:
+ Sun 15 Dec 2024 10:00:00 PM CET (in 4 days)
+ Sun 22 Dec 2024 10:00:00 PM CET (in 11 days)
+ Sun 29 Dec 2024 10:00:00 PM CET (in 18 days)
+@end example
+
+You can also list files subject to rotation with @command{herd files
+log-rotation} and trigger rotation manually with @command{herd trigger
+log-rotation}.
+
+@defvar log-rotation-service-type
+This is the type of the log rotation service. Its associated value must
+be a @code{log-rotation-configuration} record, as discussed below.
+@end defvar
+
+@c %start of fragment
+
+@deftp {Data Type} log-rotation-configuration
+Available @code{log-rotation-configuration} fields are:
+
+@table @asis
+@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)
+Dependencies of the log rotation Shepherd service.
+
+@item @code{calendar-event} (type: gexp)
+Gexp containing the @dfn{calendar event} when log rotation occurs.
+@xref{Timers,,,shepherd,The GNU Shepherd Manual}, for more information
+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)
+The compression method used for rotated log files, one of @code{'none},
+@code{'gzip}, and @code{'zstd}.
+
+@item @code{expiry} (type: gexp-or-integer)
+Age in seconds after which a log file is deleted.
+
+@item @code{size-threshold} (type: gexp-or-integer)
+Size in bytes below which a log file is @emph{not} rotated.
+
+@end table
+
+@end deftp
+
+
+@c %end of fragment
+
+@subheading Rottlog
+
+An alternative log rotation service relying on GNU@tie{}Rot[t]log, a log
+rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}), is also
+provided.
This service is part of @code{%base-services}, and thus enabled by
default, with the default settings, for commonly encountered log files.
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index 571af6a04e..deaa3b6c89 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
-;;; Copyright © 2016-2024 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016-2025 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>
;;; Copyright © 2024 Gabriel Wicki <gabriel@erlikon.ch>
@@ -45,7 +45,18 @@ (define-module (gnu services admin)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:use-module (ice-9 vlist)
- #:export (%default-rotations
+ #:export (log-rotation-configuration
+ log-rotation-configuration?
+ log-rotation-configuration-provision
+ log-rotation-configuration-requirement
+ log-rotation-configuration-calendar-event
+ log-rotation-configuration-external-log-files
+ log-rotation-configuration-compression
+ log-rotation-configuration-expiry
+ log-rotation-configuration-size-threshold
+ log-rotation-service-type
+
+ %default-rotations
%rotated-files
log-rotation
@@ -112,14 +123,105 @@ (define-module (gnu services admin)
;;; Commentary:
;;;
-;;; This module implements configuration of rottlog by writing
-;;; /etc/rottlog/{rc,hourly|daily|weekly}. Example usage
-;;;
-;;; (mcron-service)
-;;; (service rottlog-service-type)
+;;; This module provides basic system administration tools: log rotation,
+;;; unattended upgrades, etc.
;;;
;;; Code:
+\f
+;;;
+;;; Shepherd's log rotation service.
+;;;
+
+(define %default-log-rotation-calendar-event
+ ;; Default calendar event when log rotation is triggered.
+ #~(calendar-event #:minutes '(0)
+ #:hours '(22)
+ #:days-of-week '(sunday)))
+
+(define (gexp-or-integer? x)
+ (or (gexp? x) (integer? x)))
+
+(define-configuration log-rotation-configuration
+ (provision
+ (list-of-symbols '(log-rotation))
+ "The name(s) of the log rotation Shepherd service."
+ empty-serializer)
+ (requirement
+ (list-of-symbols (if for-home? '() '(user-processes)))
+ "Dependencies of the log rotation Shepherd service."
+ empty-serializer)
+ (calendar-event
+ (gexp %default-log-rotation-calendar-event)
+ "Gexp containing the @dfn{calendar event} when log rotation occurs.
+@xref{Timers,,, shepherd, The GNU Shepherd Manual}, for more information on
+calendar events."
+ empty-serializer)
+ (external-log-files
+ (list-of-strings '())
+ "List of file names, external log files that should also be
+rotated."
+ empty-serializer)
+ (compression
+ (symbol 'zstd)
+ "The compression method used for rotated log files, one of
+@code{'none}, @code{'gzip}, and @code{'zstd}."
+ empty-serializer)
+ (expiry
+ (gexp-or-integer #~(%default-log-expiry))
+ "Age in seconds after which a log file is deleted."
+ empty-serializer)
+ (size-threshold
+ (gexp-or-integer #~(%default-rotation-size-threshold))
+ "Size in bytes below which a log file is @emph{not} 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))))))
+
+(define log-rotation-service-type
+ (service-type
+ (name 'log-rotation)
+ (description
+ "Periodically rotate log files using the Shepherd's log rotation service.
+Run @command{herd status log-rotation} to view its status, @command{herd files
+log-rotation} to list files subject to log rotation.")
+ (extensions (list (service-extension shepherd-root-service-type
+ log-rotation-shepherd-services)))
+ (compose concatenate)
+ (extend (lambda (config log-files)
+ (log-rotation-configuration
+ (inherit config)
+ (external-log-files
+ (append (log-rotation-configuration-external-log-files config)
+ log-files)))))
+ (default-value (log-rotation-configuration))))
+
+\f
+;;;
+;;; Rottlog + mcron.
+;;;
+
(define-record-type* <log-rotation> log-rotation make-log-rotation
log-rotation?
(files log-rotation-files) ;list of strings
--
2.47.1
next prev parent reply other threads:[~2025-01-08 17:44 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 22:55 [bug#74860] [PATCH 00/10] Using the Shepherd's log rotation service Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 01/10] gnu: shepherd@1.0: Add dependency on gzip and zstd Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 02/10] services: Add ‘log-rotation-service-type’ Ludovic Courtès
2025-01-02 14:19 ` Maxim Cournoyer
2025-01-04 18:16 ` Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 03/10] services: log-cleanup: Rewrite as a Shepherd timer Ludovic Courtès
2025-01-02 14:24 ` Maxim Cournoyer
2024-12-13 22:58 ` [bug#74860] [PATCH 04/10] services: unattended-upgrade: " Ludovic Courtès
2025-01-02 14:28 ` Maxim Cournoyer
2024-12-13 22:58 ` [bug#74860] [PATCH 05/10] services: Switch from mcron + Rottlog to Shepherd’s log rotation Ludovic Courtès
2025-01-02 14:41 ` Maxim Cournoyer
2024-12-13 22:58 ` [bug#74860] [PATCH 06/10] services: rottlog: Deprecate Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 07/10] DRAFT news: Add entry for ‘rottlog-service-type’ deprecation Ludovic Courtès
2024-12-14 18:34 ` pelzflorian (Florian Pelz)
2024-12-17 14:25 ` Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 08/10] home: services: Add log rotation service Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 09/10] home: Define ‘%base-home-services’ Ludovic Courtès
2025-01-02 14:34 ` Maxim Cournoyer
2024-12-13 22:58 ` [bug#74860] [PATCH 10/10] home: Add log rotation to ‘%base-home-services’ Ludovic Courtès
2025-01-02 14:34 ` Maxim Cournoyer
2024-12-13 23:20 ` [bug#74860] [PATCH 00/10] Using the Shepherd's log rotation service Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 00/12] " Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 01/12] gnu: shepherd@1.0: Add dependency on gzip and zstd Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 02/12] system: Add zstd to ‘%base-packages’ Ludovic Courtès
2025-01-08 17:41 ` Ludovic Courtès [this message]
2025-01-08 17:41 ` [bug#74860] [PATCH v2 04/12] services: log-cleanup: Rewrite as a Shepherd timer Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 05/12] services: unattended-upgrade: " Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 06/12] services: Switch from mcron + Rottlog to Shepherd’s log rotation Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 07/12] services: rottlog: Deprecate Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 08/12] DRAFT news: Add entry for ‘rottlog-service-type’ deprecation Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 09/12] home: services: Add log rotation service Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 10/12] home: Define ‘%base-home-services’ Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 11/12] home: Add log rotation to ‘%base-home-services’ Ludovic Courtès
2025-01-08 17:41 ` [bug#74860] [PATCH v2 12/12] DRAFT news: Add entry for ‘%base-home-services’ Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 00/12] Using the Shepherd's log rotation service Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 01/12] gnu: shepherd@1.0: Add dependency on gzip and zstd Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 02/12] system: Add zstd to ‘%base-packages’ Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 03/12] services: Add ‘log-rotation-service-type’ Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 04/12] services: log-cleanup: Rewrite as a Shepherd timer Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 05/12] services: unattended-upgrade: " Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 06/12] services: Switch from mcron + Rottlog to Shepherd’s log rotation Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 07/12] services: rottlog: Deprecate Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 08/12] DRAFT news: Add entry for ‘rottlog-service-type’ deprecation Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 09/12] home: services: Add log rotation service Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 10/12] home: Define ‘%base-home-services’ Ludovic Courtès
2025-01-08 21:51 ` [bug#74860] [PATCH v3 11/12] home: Add log rotation to ‘%base-home-services’ Ludovic Courtès
2025-01-08 21:52 ` [bug#74860] [PATCH v3 12/12] DRAFT news: Add entry for ‘%base-home-services’ Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3c927596ee81d985d925c8b72bf4a3f33336b457.1736357737.git.ludo@gnu.org \
--to=ludo@gnu.org \
--cc=74860@debbugs.gnu.org \
--cc=maxim.cournoyer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).