From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id MPbIJB29XGf7iwAAe85BDQ:P1 (envelope-from ) for ; Fri, 13 Dec 2024 23:02:53 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id MPbIJB29XGf7iwAAe85BDQ (envelope-from ) for ; Sat, 14 Dec 2024 00:02:53 +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=n2ddFyYm; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=exEidfpg; 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=1734130973; 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=dvxhhL/9XI8qzsKhTMu4ubH9hhjyHnhJlx36vI9w56w=; b=BlymONPENgiwSVYoJXAJ5eIJv5wb4oEEHQp8GpJD6O6PKsKZkRCF1NYKsOiFTLeNS+4oT7 lPFzPjpgLe+n/dxJe0a6un03VRn9EZIdRQBx3Xza/yBv6TWeFopGwDmICMzGiZ6r/hjZI9 TCDowSKcUjJZneiMOBD8nUuQ1dT2z1xSrPQDeEjHCR0AzkikgE6SJBPxnjNoXOl7XQ5dPk MDVS1ZgAldRmf2MAQMPJZ1DkS4Zy3QuQIWC8f/1pDXy4El0IjyiIhijiQhsCT6VvHBy+z6 woxKBk4Fh9EvmV7TBYCivBPCGPk0lGs+FEjMjGtHCZCWJbwBKnNE8tuuICfXVg== 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=n2ddFyYm; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=exEidfpg; 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=1734130973; a=rsa-sha256; cv=none; b=UnrQ5USpYt4jTo32e1gIikKP0ETAlmedj3L5XweftktGkLvXAjjV407X7npvhzfZg2wWSL eCayyWLOVn+oV6xxIJ8WYFy+HMpy0Va7RHX2+G9Q9Xx+VdlWlXHaK88Upkc+Y0equbajHB tcM+Gr2kGWSBlFFzrZcQva4BM9W5VdcSVDXnNXDKX7O21adlw5fw5JOvbEP1oh4nTxGa29 MFBLqIW/kRXCR0H85MrPuP7mEdmpZAaaxedbLvEiF3L7h0JgDoXm7z93Rylr9YQDBViq9R l8uX/Ezm5xX0ySw6KdVJIzgysXtqWRev7k7Nai1E4YxIiemABUrlEP2RkOsZPw== 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 2710E46DA5 for ; Sat, 14 Dec 2024 00:02:53 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMEfo-0003zb-2N; Fri, 13 Dec 2024 18:02: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 1tMEfc-0003wY-Vi for guix-patches@gnu.org; Fri, 13 Dec 2024 18:02:05 -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 1tMEfb-0002l6-Fx; Fri, 13 Dec 2024 18:02:03 -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=JRkADmX1N01CEy04CsN/j0Ua8rLTsUFJpNlG2OSfkxI=; b=n2ddFyYmj2ddHP7cQeM9t3p8CcBxD1vdtLrpJFttoeQyT8plV4K0AeFgmWBxCaE3/Q9PNLtGg25N3ry+/C0mXqhM5JOG/xtJd47eZk5K7x1ZiiNgtfTfYzlPf8zfp8ZgwErH9gu9I1wuTLsUyE72926pZFU9Swrw84wKDPXpHFVcSIzxkoMvPWp4pnn4OXfoRZMuXtkKSib7AzIW4CNXesI5M7jjkCp7r4lEtGfaXFI1lwbpupJ7SxO4GxW7YQhF3n9P2BjVcZFwxI54E3poh1LKEhJuWQG5F9eV0/DcEpMc00biwXeQUNenSUGIKZ75keW2GXWxt2B3pJURgrkgng==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMEfa-0001Y5-9Z; Fri, 13 Dec 2024 18:02:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH 02/10] 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: Fri, 13 Dec 2024 23:02: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.17341308765772 (code B ref 74860); Fri, 13 Dec 2024 23:02:02 +0000 Received: (at 74860) by debbugs.gnu.org; 13 Dec 2024 23:01:16 +0000 Received: from localhost ([127.0.0.1]:44553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMEep-0001Uw-ST for submit@debbugs.gnu.org; Fri, 13 Dec 2024 18:01:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMEel-0001UJ-Dq for 74860@debbugs.gnu.org; Fri, 13 Dec 2024 18:01:12 -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 1tMEcZ-0001mJ-CA; Fri, 13 Dec 2024 17:58:57 -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=JRkADmX1N01CEy04CsN/j0Ua8rLTsUFJpNlG2OSfkxI=; b=exEidfpgm66+qIGqlO6v wmHw8fR/wk3O8QiVacOjRoUvW+tZBjeiB4bvIzuuWfp3/dzIFJdg5xK0uI9tvY8oZmF0MLRK9rY2l YKeq7aWk5iY64ZaQrsC3wTz63UdjkRYlL1rd3QySzsmWbzWPwe5lTTMfe0wTdVokngQLm5QegEhZy 2roDbUPxr3iXoTxO04fO7aN0qAGR38pU13oF1TJb4nkl/x0Kh55TM47TJIE3JxQHsS1aYzdzWFxFW 1Ep4XFa9pfroJmImuCeOiM/W6tEl/2Sh7oXvvyEdi1mypZLxivBr2Yc6x59sIwCuoL90rHS5MHAU6 OMCSyxkaSSU8MQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 Dec 2024 23:58:22 +0100 Message-ID: <97dd04a5fbb49bcacc4b7d61749f64c8c6fae9d5.1734129908.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 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-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 1.93 X-Spam-Score: 1.93 X-Migadu-Queue-Id: 2710E46DA5 X-TUID: roPZDO6NV8DG * 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 | 73 +++++++++++++++++++++++++++++++- gnu/services/admin.scm | 95 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 159 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index a2915de954..89a85961ac 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20766,8 +20766,77 @@ 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 + +@deftp {Data Type} log-rotation-configuration +This data type represents the configuration of the log rotation service. +Its defaults should be good for most use cases. + +@table @asis +@item @code{calendar-event} (default: every Sunday at 10PM) +This is a 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{'()}) +This is a list of file names, external log files that should also be +rotated. + +@item @code{compression} (default: @code{'gzip}) +This is the compression method used for rotated log files, one of +@code{'none}, @code{'gzip}, and @code{'zstd}. + +@item @code{expiry} (default: @code{#~(%default-log-expiry)}) +Age in seconds after which a log file is deleted. + +@item @code{size-threshold} @ + (default: @code{#~(%default-rotation-size-threshold)}) +Size in bytes below which a log file is @emph{not} rotated. + +@item @code{provision} (default: @code{'(log-rotation)}) +@itemx @code{requirement} (default: @code{'(user-processes)}) +These are the name(s) and dependencies of the log rotation Shepherd +service. +@end table +@end deftp + +@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 24ff659a01..5e1c197d78 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-2023 Ludovic Courtès +;;; Copyright © 2016-2024 Ludovic Courtès ;;; Copyright © 2020 Brice Waegeneire ;;; Copyright © 2023 Giacomo Leidi ;;; @@ -39,7 +39,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 @@ -97,14 +108,84 @@ (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-record-type* + log-rotation-configuration make-log-rotation-configuration + log-rotation-configuration? + (provision log-rotation-configuration-provision (default '(log-rotation))) + (requirement log-rotation-configuration-requirement + (default (if for-home? '() '(user-processes)))) + (calendar-event log-rotation-configuration-calendar-event + (default %default-log-rotation-calendar-event)) + (external-log-files log-rotation-configuration-external-log-files + (default '())) + (compression log-rotation-configuration-compression (default 'gzip)) + (expiry log-rotation-configuration-expiry + (default #~(%default-log-expiry))) + (size-threshold log-rotation-configuration-size-threshold + (default #~(%default-rotation-size-threshold)))) + +(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.46.0