From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 4GIVAg30fmeqdAAA62LTzQ:P1 (envelope-from ) for ; Wed, 08 Jan 2025 21:54:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 4GIVAg30fmeqdAAA62LTzQ (envelope-from ) for ; Wed, 08 Jan 2025 22:54:21 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=EjORAMEV; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=g+qsZy9C; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736373260; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=TkTd6mxAL3Zb+YpMzBvhNYZWf4yc2CzHsicshlcRKpM=; b=cYoyc9qPc+kUs6TG9CwZ6LsWKFiSNTIBh6uiRLUUtg1CGDFXVjlIE+0DQYqXNBj+XttSgK rx05WSIy+pF8HbDWW9JdVUVy4EX4pdGUr3NA2NTuy6GxGAkUhlgNvIUJPur/8B6/pl09oQ BQ0hmFQgH1XiE44zM1UdcuFUsUKOGQRkWE+sfZPXqgb2jCSxN2aiol0xceer9cog29D89z 2Jlfuu5bdf1XI/Nbc7By0jsEfVrs0dSsWXAMhjvizSrsrToI1gURwQ+9Dk5I8wmYqyU61i Pi9QJho0MxN2Sq3bsuozdXJGOvkwXWW3egrYeiMtCJK0zpqmzbYIHRCR+n7PbQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=EjORAMEV; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=g+qsZy9C; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736373260; a=rsa-sha256; cv=none; b=GkOtNLVVT1R/X92DzqwzO8sB4tGm4i4471X+354FjPGXIQSZKWYcrCMSco7VMlGYbw7EQu jB56dW6orYssdyiea37ppoqLnbIZ0nsmfdjhneKYCZv8wlPpBxmgzHcfGJoApizyeTarD8 snZrD+HvcnFt22z21U55FJ0ohRkAjf8Vt4Gr+df7XewZQic/m/k9qc+LhyGHVHuJzBqoVW adjKXmF2fY4tYITY6PJUoNyIXEZzj6FNsRpxPqMdrzOtRzZ7+xiSyNT6K1UIDG3S2OVuAo g5WXtWh+W07SJoX9lXQGlodmvxt49amEmPvhvT8tg09WWpCI+nvhT48UE8JkaA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B40949E601 for ; Wed, 08 Jan 2025 22:54:20 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVe0G-0000Vx-Al; Wed, 08 Jan 2025 16:54:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVe02-0008VV-Qv for guix-patches@gnu.org; Wed, 08 Jan 2025 16:54:03 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVe02-0004GC-Hf; Wed, 08 Jan 2025 16:54:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Laf33kyswaXFBPb6jed6TOukZ6/HqKIdR+p2dgqVirI=; b=EjORAMEVZUWd0HUwslqCFCuAAiAxRZPNnrImbEjRtaKFo62u5B1FM2WMNGvu0z8sImOBJGMRa/j7628pCvDkrx0bbEemDRx959sK+K8Llv+oaGxRS0mev6EqRdIhnVRGnTak4bu99bXItZk0pZZiWButqKklYkF27ZWLyJwRxyIpf+lDzxyzTwko63LArbCVXcY7+VO4spUKBqT7SPLbtFUoJo+/3ywz77cgvvSAfF3pCQPbbWlQH7GkBceK/iRBGcSLQqEomr+3srIiVGZWYcdjP8NOb9/3ZjDtORKrX8NPysVn1DS9vgHTUxloxjcDET4PCrAi6GFtlBMT+LKo7g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tVe02-0005XQ-DD; Wed, 08 Jan 2025 16:54:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH v3 03/12] services: Add =?UTF-8?Q?=E2=80=98log-rotation-service-type=E2=80=99.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 08 Jan 2025 21:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74860@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 74860-submit@debbugs.gnu.org id=B74860.173637318921151 (code B ref 74860); Wed, 08 Jan 2025 21:54:02 +0000 Received: (at 74860) by debbugs.gnu.org; 8 Jan 2025 21:53:09 +0000 Received: from localhost ([127.0.0.1]:49304 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tVdzA-0005Ur-1J for submit@debbugs.gnu.org; Wed, 08 Jan 2025 16:53:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37962) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tVdz1-0005SY-4o for 74860@debbugs.gnu.org; Wed, 08 Jan 2025 16:53:00 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVdyv-00045M-LZ; Wed, 08 Jan 2025 16:52:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=Laf33kyswaXFBPb6jed6TOukZ6/HqKIdR+p2dgqVirI=; b=g+qsZy9C6k0Nu2Od8HwW vnD1WiNCD5Dd0vdzIEYS5HL6qFe47UYBYqTvWsq8ICBapQsz0fwgsN85RyvVjlN/AL8opZsJeVbWO /7KpMYw9nDvPF+mlWp7EuA/ilzjoVUfd2fsaMdaV5po5YW1hXU99yywoNQ9u79Jrt7Ws62D8f8X1f Jy4Yt8WuXAUHYdXE8c8kk2EdCdLrZObdKLqHbTbzN24vekuAPOVwJOX1eLv+T/JeUqEX7HZwzIISk r10KsJGx2fW9Fh2UTXN5u2/5oV//v1GPrKoWnd3jpD7TKrYIqhdrdbWA9wxzASIjlNj2sTDNQdoXn wwUiWTWU9n3jag==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 8 Jan 2025 22:51:51 +0100 Message-ID: <3c927596ee81d985d925c8b72bf4a3f33336b457.1736373022.git.ludo@gnu.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.78 X-Spam-Score: -3.78 X-Migadu-Queue-Id: B40949E601 X-Migadu-Scanner: mx10.migadu.com X-TUID: BtLSzt50ZmKQ * gnu/services/admin.scm (%default-log-rotation-calendar-event): New variable. (): 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 -;;; Copyright © 2016-2024 Ludovic Courtès +;;; Copyright © 2016-2025 Ludovic Courtès ;;; Copyright © 2020 Brice Waegeneire ;;; Copyright © 2023 Giacomo Leidi ;;; Copyright © 2024 Gabriel Wicki @@ -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: + +;;; +;;; 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)))) + + +;;; +;;; Rottlog + mcron. +;;; + (define-record-type* log-rotation make-log-rotation log-rotation? (files log-rotation-files) ;list of strings -- 2.47.1