From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id EN5PDdlUMWMqFQAAbAwnHQ (envelope-from ) for ; Mon, 26 Sep 2022 09:29:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id GEFoDNlUMWOPagAAG6o9tA (envelope-from ) for ; Mon, 26 Sep 2022 09:29:29 +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 82972105DD for ; Mon, 26 Sep 2022 09:29:28 +0200 (CEST) Received: from localhost ([::1]:54608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ociYR-00025e-MG for larch@yhetil.org; Mon, 26 Sep 2022 03:29:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ociY2-00024E-7u for guix-patches@gnu.org; Mon, 26 Sep 2022 03:29:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50059) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ociY1-00066O-Vr for guix-patches@gnu.org; Mon, 26 Sep 2022 03:29:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ociY1-0008Hp-Pz for guix-patches@gnu.org; Mon, 26 Sep 2022 03:29:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58086] [PATCH] gnu: Add fstrim-service-type. Resent-From: iyzsong@envs.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Sep 2022 07:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58086 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58086@debbugs.gnu.org Cc: =?UTF-8?Q?=E5=AE=8B=E6=96=87=E6=AD=A6?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.166417732431823 (code B ref -1); Mon, 26 Sep 2022 07:29:01 +0000 Received: (at submit) by debbugs.gnu.org; 26 Sep 2022 07:28:44 +0000 Received: from localhost ([127.0.0.1]:49137 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ociXk-0008HD-Bj for submit@debbugs.gnu.org; Mon, 26 Sep 2022 03:28:44 -0400 Received: from lists.gnu.org ([209.51.188.17]:44722) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ociXh-0008H3-EN for submit@debbugs.gnu.org; Mon, 26 Sep 2022 03:28:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ociXh-00023o-8j for guix-patches@gnu.org; Mon, 26 Sep 2022 03:28:41 -0400 Received: from mail.envs.net ([5.199.136.28]:36160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ociXf-00063j-9D for guix-patches@gnu.org; Mon, 26 Sep 2022 03:28:40 -0400 Received: from localhost (mail.envs.net [127.0.0.1]) by mail.envs.net (Postfix) with ESMTP id 9384938A0FAF; Mon, 26 Sep 2022 07:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=envs.net; s=modoboa; t=1664177307; bh=9/+nvn8WChAUUV+3J7HnA2dmlJjtknS7GG63KUWr3Y4=; h=From:To:Cc:Subject:Date:From; b=p0OOb0EMde0lm0sroadJDxsHWtZjD7x/xbFjEjrYCIq0oh3TZcoVftEzKWd8Hc8EV td3kVvUn7BUhhBdqHmDiUf61qPC5E9t8ceVZpGNX2/NElLOzT2H9bYf88C6Y+O9FbN n4Fh9yv/Ct8IcZZFx+NfU0Z/PfH2xMAKt0oXtZG7131nhQxYeb1LrwYPhqhwxE+X+w Y/1K4dSVX1GWNiaGM6TR1USWXa0OBBfXDwhHWI+HHaUN3gKANAkf492Yoi7ntK/7h9 MAsUyAvsljp9/zIZQc8Wb72Rec8yhPR8bqzKo03XOj5hCoLRorz4ThuH89YQwsWAft 6sgLlVo/KkdnHfr7N1BaIlM8C3d15f1e1nqdJwiwzpcE0s9Ob/Nr4L10sSyfOJh/V1 oT+SnlY3TbUlsZCw1vYUyxdmXwvjvb/oTHWuXPfGQOKza9hrxzTLOtf8uOzeKi0Gbz RtRGRAu4o76CxT0y64R3ZX4VOThxvMMvTY8Q+WWJeblyJ8wHHv49KA5jZccDqFdLUz tI5f1X4VAkcbI0R33ClhqGlUjcmg22qX301k9eptQ3CQ6y762KzwI9Sjb60Rq8416y F9hFpX+5x6nNfveQ3sH4ZHiL5k4+qCuZlS0WoXlElaBmRaxiqXBSPFnHFFnL6Bkzed 6000qHgu3rIYeYBJeGlhW4fY= X-Virus-Scanned: Debian amavisd-new at mail.envs.net Received: from mail.envs.net ([127.0.0.1]) by localhost (mail.envs.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2kjrR0VJni_Q; Mon, 26 Sep 2022 07:28:24 +0000 (UTC) Received: from localhost (unknown [182.150.116.135]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.envs.net (Postfix) with ESMTPSA; Mon, 26 Sep 2022 07:28:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id efc52026; Mon, 26 Sep 2022 07:28:27 +0000 (UTC) Date: Mon, 26 Sep 2022 15:28:25 +0800 Message-Id: <20220926072825.4689-1-iyzsong@envs.net> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=5.199.136.28; envelope-from=iyzsong@envs.net; helo=mail.envs.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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" Reply-to: iyzsong@envs.net X-ACL-Warn: , iyzsong--- via Guix-patches From: iyzsong--- via Guix-patches via 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=1664177368; h=from:from:sender:sender:reply-to: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=c45A11sn+C80VODq4wzRzpuddmmotz5Oor9Eh3t7QjQ=; b=iCS8YYuMsshaEhPqFhAbga9uPIFbrGiR3UCbAbB/a5vBujPy731ALARvuLgwBSOEkrwzkP NJCISle4WPV4NEgpXCVVa7mQNNU4xVjrYSosFg+AJK+h1yHKhr/qsfoEyfai3MWicu2Shd yOZSabyYZ2MN1x6eucA9JZNPTSOV3nDobWpFTXpB9zoIy8T1nTr0YTUICISQGQ2ySgrWIo +4bM8uy4nK07USToVhL2u4y7/wm41pFO+JEPKq49wQZtRFP3a7KCe3tBicLkpGc1KLnrka mPPMFM4XeYRyQeVuJxEyGZXPKxOaRWpfJ+Y0Yp/P5/ve+smtcLxDj/l4FOneOQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664177368; a=rsa-sha256; cv=none; b=TGfwN185eYLcTrdzMtFOkKsO+ZoNzEpSQOpy1cb9oSbo6m3fpvQXKA3xXvy8faNOvpF6Ke 3XDihDBeqRPC5OH/lv6nmGmV1fP+8IZ2AaxUfIRSqkIuYsLbQpp3hE697E0dThWbKwvCk9 8cPFA/7eSnVjBxjEJriDPzYydV7WP/vZ9Fn6AQ5l1nUkhXndr1dc0EIbUBtUaKJP/h2lzH VLi1G5m+grc1OUQaKLm+Fa1mjtxuTtM4jtdptsRYG1oUiejgPPoDVhGUb1d4cRpFzxLfmQ GZN4dIw4B+HdVh43dn8tuu6hUme8yf6TGhFInmIbiKyamlF8Ch0Qfk4eDP9KJA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=envs.net header.s=modoboa header.b=p0OOb0EM; 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.14 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=envs.net header.s=modoboa header.b=p0OOb0EM; 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: 82972105DD X-Spam-Score: -3.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: lML3PB9FwRfO From: 宋文武 A timestamp file "/var/lib/mcron/fstrim.stamp" is used to ensure we will catch up on missed job runs when the system was powered down. * gnu/services/mcron.scm (%mcron-activation): New extension to create '/var/lib/mcron'. * gnu/services/admin.scm (fstrim-configuration): New record type. (fstrim-mcron-jobs): New procedure. (fstrim-service-type): New service type. --- gnu/services/admin.scm | 56 +++++++++++++++++++++++++++++++++++++++++- gnu/services/mcron.scm | 8 ++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 252bedb0bd..2b22fc5b33 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -21,6 +21,7 @@ (define-module (gnu services admin) #:use-module (gnu packages admin) #:use-module (gnu packages certs) + #:use-module (gnu packages linux) #:use-module (gnu packages package-management) #:use-module (gnu services) #:use-module (gnu services mcron) @@ -30,6 +31,7 @@ (define-module (gnu services admin) #:use-module (guix packages) #:use-module (guix records) #:use-module (srfi srfi-1) + #:use-module (ice-9 match) #:use-module (ice-9 vlist) #:export (%default-rotations %rotated-files @@ -63,7 +65,11 @@ (define-module (gnu services admin) unattended-upgrade-configuration-services-to-restart unattended-upgrade-configuration-system-expiration unattended-upgrade-configuration-maximum-duration - unattended-upgrade-configuration-log-file)) + unattended-upgrade-configuration-log-file + + fstrim-service-type + fstrim-configuration + fstrim-configuration?)) ;;; Commentary: ;;; @@ -376,4 +382,52 @@ (define unattended-upgrade-service-type "Periodically upgrade the system from the current configuration.") (default-value (unattended-upgrade-configuration)))) + +;;; +;;; fstrim. +;;; + +(define-record-type* + fstrim-configuration make-fstrim-configuration fstrim-configuration? + (command fstrim-configuration-command + (default + (list (file-append util-linux "/sbin/fstrim") + "--verbose" "--quiet-unsupported" + "--listed-in" "/etc/fstab"))) + (interval fstrim-configuration-interval (default (* 60 60 24 7)))) ; weekly + +;;; By storing the time of job's last run in a file, we can catch up on missed +;;; runs when the system was powered down. +(define fstrim-mcron-stamp "/var/lib/mcron/fstrim.stamp") + +(define fstrim-mcron-jobs + (match-lambda + (($ command interval) + (list + #~(job + (let ((last-time + (catch #t + (lambda () + (with-input-from-file #$fstrim-mcron-stamp read)) + ;; We schedule a first run immediately. + (const 0)))) + (lambda (current-time) + (let ((next-time (max current-time (+ #$interval last-time)))) + (set! last-time next-time) + next-time))) + (lambda () + (apply system* '#$command) + (with-output-to-file #$fstrim-mcron-stamp + (lambda () (write (current-time)))))))))) + +(define fstrim-service-type + (service-type + (name 'fstrim) + (extensions + (list (service-extension mcron-service-type + fstrim-mcron-jobs))) + (description + "Periodically discard unused blocks on filesystems.") + (default-value (fstrim-configuration)))) + ;;; admin.scm ends here diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm index 23760ebda4..833d979ab4 100644 --- a/gnu/services/mcron.scm +++ b/gnu/services/mcron.scm @@ -154,6 +154,12 @@ (define mcron-shepherd-services (actions (list (shepherd-schedule-action mcron files))))))))) +(define %mcron-activation + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (mkdir-p "/var/lib/mcron")))) + (define mcron-service-type (service-type (name 'mcron) (description @@ -161,6 +167,8 @@ (define mcron-service-type (extensions (list (service-extension shepherd-root-service-type mcron-shepherd-services) + (service-extension activation-service-type + (const %mcron-activation)) (service-extension profile-service-type (compose list mcron-configuration-mcron)))) -- 2.37.3