From patchwork Thu Mar 31 21:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38254 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6869527BBEA; Thu, 31 Mar 2022 22:23:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D5CB927BBE9 for ; Thu, 31 Mar 2022 22:23:19 +0100 (BST) Received: from localhost ([::1]:50732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1na2GF-0004gH-0u for patchwork@mira.cbaines.net; Thu, 31 Mar 2022 17:23:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1na2Fy-0004fE-VE for guix-patches@gnu.org; Thu, 31 Mar 2022 17:23:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46118) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1na2Fy-00071I-MK for guix-patches@gnu.org; Thu, 31 Mar 2022 17:23:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1na2Fy-00020g-EU for guix-patches@gnu.org; Thu, 31 Mar 2022 17:23:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54659] [PATCH 1/2] services: Add 'log-cleanup-service-type'. References: <20220331212038.24214-1-ludo@gnu.org> In-Reply-To: <20220331212038.24214-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 31 Mar 2022 21:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54659 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54659@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54659-submit@debbugs.gnu.org id=B54659.16487617457654 (code B ref 54659); Thu, 31 Mar 2022 21:23:02 +0000 Received: (at 54659) by debbugs.gnu.org; 31 Mar 2022 21:22:25 +0000 Received: from localhost ([127.0.0.1]:40013 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1na2FM-0001zO-M9 for submit@debbugs.gnu.org; Thu, 31 Mar 2022 17:22:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40356) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1na2FL-0001z6-Cl for 54659@debbugs.gnu.org; Thu, 31 Mar 2022 17:22:23 -0400 Received: from [2001:470:142:3::e] (port=41448 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1na2FG-0006z5-4j; Thu, 31 Mar 2022 17:22:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=5oVRwGy4dPOqU71qvqM4vT5EfNtvKIHqDJ/pV1qfQug=; b=mnY+hDX3BcaZDk LqmwkBO5kV/JRJa47/2ts231NATQQJgJa+dR5/96ZsBCywFQ5y/EgG4tPYoGPTffqdPzlqj2vXfsJ IRwZf7+74Glo3lC4AGlpAXGAOOFaFxDhFQalNldoved30TkdWmxYoOD/3grUHCrNevAJtG71s04rh JdIlfvvuRasPyrO1U26DxqAAjMw6KBOlXLG63Ztn9FccxNwhVsav8foM13YC6Yj3dFEU9xkGMbMPa V3Eqh4rrOkhqk85/faytIjdoq1S8h/Y6IF1/uai1SsI9gsyG4AJD8CxEqIgjT4E3iIMoEJCr+1hA3 DHpIfC7ZjipAIKNfOr/w==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:53161 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1na2FF-0002H8-Jm; Thu, 31 Mar 2022 17:22:17 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 31 Mar 2022 23:22:07 +0200 Message-Id: <20220331212208.24385-1-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/services/admin.scm (): New record type. (log-cleanup-program, log-cleanup-mcron-jobs): New procedures. (log-cleanup-service-type): New variable. * doc/guix.texi (Log Rotation): Document it. --- doc/guix.texi | 28 ++++++++++++++++++++++ gnu/services/admin.scm | 53 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index e8ef4286be..ad2763ec8a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -17641,6 +17641,34 @@ The list of syslog-controlled files to be rotated. By default it is: "/var/log/maillog")}. @end defvr +Some log files just need to be deleted periodically once they are old, +without any other criterion and without any archival step. This is the +case of build logs stored by @command{guix-daemon} under +@file{/var/log/guix/drvs} (@pxref{Invoking guix-daemon}). The +@code{log-cleanup} service addresses this use case. + +@defvr {Scheme Variable} log-cleanup-service-type +This is the type of the service to delete old logs. Its value must be a +@code{log-cleanup-configuration} record as described below. +@end defvr + +@deftp {Data Type} log-cleanup-configuration +Data type representing the log cleanup configuration + +@table @asis +@item @code{directory} +Name of the directory containing log files. + +@item @code{expiry} (default: @code{(* 6 30 24 3600)}) +Age in seconds after which a file is subject to deletion (six months by +default). + +@item @code{schedule} (default: @code{"30 12 01,08,15,22 * *"}) +String or gexp denoting the corresponding mcron job schedule +(@pxref{Scheduled Job Execution}). +@end table +@end deftp + @node Networking Setup @subsection Networking Setup diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 043517262f..3096acdf5a 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, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2016-2022 Ludovic Courtès ;;; Copyright © 2020 Brice Waegeneire ;;; ;;; This file is part of GNU Guix. @@ -46,6 +46,13 @@ (define-module (gnu services admin) rottlog-service rottlog-service-type + log-cleanup-service-type + log-cleanup-configuration + log-cleanup-configuration? + log-cleanup-configuration-directory + log-cleanup-configuration-expiry + log-cleanup-configuration-schedule + unattended-upgrade-service-type unattended-upgrade-configuration unattended-upgrade-configuration? @@ -191,6 +198,50 @@ (define rottlog-service-type rotations))))) (default-value (rottlog-configuration)))) + +;;; +;;; Build log removal. +;;; + +(define-record-type* + log-cleanup-configuration make-log-cleanup-configuration + log-cleanup-configuration? + (directory log-cleanup-configuration-directory) ;string + (expiry log-cleanup-configuration-expiry ;integer (seconds) + (default (* 6 30 24 3600))) + (schedule log-cleanup-configuration-schedule ;string or gexp + (default "30 12 01,08,15,22 * *"))) + +(define (log-cleanup-program directory expiry) + (program-file "delete-old-logs" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + + (let* ((now (car (gettimeofday))) + (logs (find-files #$directory + (lambda (file stat) + (> (- now (stat:mtime stat)) + #$expiry))))) + (format #t "deleting ~a log files from '~a'...~%" + (length logs) #$directory) + (for-each delete-file logs)))))) + +(define (log-cleanup-mcron-jobs configuration) + (match-record configuration + (directory expiry schedule) + (list #~(job #$schedule + #$(log-cleanup-program directory expiry))))) + +(define log-cleanup-service-type + (service-type + (name 'log-cleanup) + (extensions + (list (service-extension mcron-service-type + log-cleanup-mcron-jobs))) + (description + "Periodically delete old log files."))) + ;;; ;;; Unattended upgrade.