From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6A9WG8IbRmJZFwEAgWs5BA (envelope-from ) for ; Thu, 31 Mar 2022 23:23:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id qJjJGMIbRmLsYgAA9RJhRA (envelope-from ) for ; Thu, 31 Mar 2022 23:23:14 +0200 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 D23F31D529 for ; Thu, 31 Mar 2022 23:23:13 +0200 (CEST) Received: from localhost ([::1]:50732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1na2G8-0004gH-Jw for larch@yhetil.org; Thu, 31 Mar 2022 17:23:12 -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 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1648761794; 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=8M32+YhUwMwtR8y6VnR636ClyLo7eKpG/5MsxJMUQtc=; b=QEuLIB29R4weTIeP7WlSddsQGCRfMAr+wFU0uwMjbIJvTf5W365OTqBbF2rgQdEWtpEart arZZzNVxAcxAnSordBaVnZBXF7LmsRCHUCbCdZdTDdJRcbFoVTv+U2ZTzOuZUjV58Dtrcb JLiGjN+0QZwNmSc5rbgmg/agKHJSsMSZzUrB09glnz5tysuGq8L4aBKsy/4NJLzyVPh0Ap KO9I1yrmc9rtT4/SHL8ntnSiGVzWoE62x1XEaaqbPS8dRXB47tGp6F88b7+ATdpx7Hfgid VhNUi8dc+u6pXiJN0BnED5vuoYz7WOBsP0frHlcwu80JmJN55b3mgrCeVfX8sQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648761794; a=rsa-sha256; cv=none; b=Lk5oIKks/oEerfnp6IOz2UXvRSnS4UNiHY8eSMsqD1AkP64DOrpd+TmX4ynmSfbhPbGILI goEwuXnSYVaf3voB8e6fzmFCkWC10OWzZfe31z22sBXTWPaU+00kOr3i4esQrxZMvAMs6/ PVL0t0N9IYxjD6EMgpGSO/t8Ta53GTEvnkq0bx1uusba9aDCJSQ2TKVixDxJ2i/9aLYXyU PsGtYiaNdHSfzz4PdY+UeceRRJE5LRYytaiGHJ07vnBlvGSmxPqbkM2xh1VzKHWZkyToFl NsPRzydpRS06yMX9Gh8n3zhBeV1NxtYcH3zjYtD/Bl9uCSl4lVetghQJCN25eg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=mnY+hDX3; dmarc=pass (policy=none) header.from=gnu.org; 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" X-Migadu-Spam-Score: -3.57 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=mnY+hDX3; dmarc=pass (policy=none) header.from=gnu.org; 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" X-Migadu-Queue-Id: D23F31D529 X-Spam-Score: -3.57 X-Migadu-Scanner: scn0.migadu.com X-TUID: UNTWAEUQ7Ru0 * 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. -- 2.34.0