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 EGKfEWq5fmc0gAAAe85BDQ:P1 (envelope-from ) for ; Wed, 08 Jan 2025 17:44:10 +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 EGKfEWq5fmc0gAAAe85BDQ (envelope-from ) for ; Wed, 08 Jan 2025 18:44:10 +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=afA1joVL; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=MgjjkdOB; 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=1736358249; 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=Fe7HZ9C7iSW6ym6Wrt0hjf/75M7Ugm9tjQd4rtYUUB2KOY8VAjAoY8YX0V58YKGy+ILhyR 50SNyVp/7EHqQoiTKzbYVVtjAB/hZHyZCMU4FXq7VRsgAniTys8OFnjvO89klWDPTrkwFI 5MtDSDAIxw3hnz21eWSQTYxRsO3pZupTbIvpK9Krf0087CV1fsFnsDnu6x9BWYwNThqmnp G4qaX3IsdFOvcea0wzesvumclPI/+uwJJRVKec8BFjMJZc8pPbCOYQySNvtEwwgceNAn2D gfq+TPBbvzE1P21G1r/Or0wWoK3/wcRPDTi6amkMhgFOfpjajUzDssXVX3+IlA== 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=afA1joVL; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=MgjjkdOB; 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=1736358249; a=rsa-sha256; cv=none; b=i7tAlIKWY1+gksgFBJJJbLcKfGEeL9idDHr56pSP7xLA/aobT3rAN+EZvyzSgGkqDAmjO5 wvH8AoV2IU5K9bzcbDL6HvB0EF8c0dKzozCrxGnoOuE2gMszAhugmfcY6aF2S0gSJBDoqU Jo/G7aDu9EX5qV7rAhFQECxiQgfY6oUDNUfszv76lQw4FqUZ8Zye/UB79MNafwGWkRHs+U 4c3HoLc/1XbXq0tbDXnzSGO7ZLZvjvzTktGM2SnfBZSa7iUG0gY5KD+OSxdYZdRS5N1LHz 7kVvL3Nndp9wiYrfgskV12JB4+CVyMPGGEV4A/o6IQ6PGSf/PtaqA5sm2O2EZw== 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 BFF7743529 for ; Wed, 08 Jan 2025 18:44:09 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVa5T-0005en-Bh; Wed, 08 Jan 2025 12:43:23 -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 1tVa5A-0005Uj-2y for guix-patches@gnu.org; Wed, 08 Jan 2025 12:43: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 1tVa59-00038w-QI; Wed, 08 Jan 2025 12:43: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=Laf33kyswaXFBPb6jed6TOukZ6/HqKIdR+p2dgqVirI=; b=afA1joVLr2sVstgev+8SkcOkaydU/Njvfj2jIyddvhGrdKFaK9KmmmbwmiY2WtuhDQFS8J7zGzRqYJX6bD7f5H3BWtDs5Yb0ytscP7jFOPSdjQL89kUzlovQeZ4dOghzKxq8w3MQPDIlI1Vy50URZAHfvI7sgodYR/wK+ITXSz84pE/5fKtzqE3aMNC9F5yMAewHWMtGTfNs00ixGImx6eMUIEQ4FRvP0q+TSkTCZOatgGKAJGKTgfo55jC44Dsd22d5napkrPxBq90yJWjUorr4Yn1+pmKqaurk3O3KxU6tk6HLuoT3N08zzc8/2+EWV3x0groAvVwU4N+3/39qGw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tVa59-0007sK-Ky; Wed, 08 Jan 2025 12:43:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH v2 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 17:43:03 +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.173635815830124 (code B ref 74860); Wed, 08 Jan 2025 17:43:03 +0000 Received: (at 74860) by debbugs.gnu.org; 8 Jan 2025 17:42:38 +0000 Received: from localhost ([127.0.0.1]:48792 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tVa4i-0007pk-Vt for submit@debbugs.gnu.org; Wed, 08 Jan 2025 12:42:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60002) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tVa4b-0007oC-FD for 74860@debbugs.gnu.org; Wed, 08 Jan 2025 12:42:30 -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 1tVa4W-0002tv-5C; Wed, 08 Jan 2025 12:42:24 -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=MgjjkdOBuc9+84+NsoSJ atnhuAHQv7Z2z/5V0SjkDarHHlPhPnXJLEhCkPV3DPYooB4NLNUL1KDAPWfadrLiykgvrEkseUAuC 48g/wPWlIWWE6Q4wzJZvBKFSnaRtJBaRLtQ65FYptJ7DHlSmxUE2bXOcpe2LEmYULxi32fVsyCkA4 rddqVBHKgd9Si5cfC54yhhfnMnZ9majjbloQM7fjOYuShR0W0c9W3/t20amkj/WErt9InCp31vBzx y17dV1i61mckkc6l+vdhP7iknOWf+98kZeBt1X7Zl08xW8znop211oP3PzJAL3OS++94maOWC4QPy 5zM7c7oU3edzkQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 8 Jan 2025 18:41:47 +0100 Message-ID: <3c927596ee81d985d925c8b72bf4a3f33336b457.1736357737.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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -0.98 X-Spam-Score: -0.98 X-Migadu-Queue-Id: BFF7743529 X-TUID: ttfs3d864rJs * 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