From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 CEnMMLPAXGPTZwAAbAwnHQ (envelope-from ) for ; Sat, 29 Oct 2022 07:57:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id eKvPL7PAXGPuHwAA9RJhRA (envelope-from ) for ; Sat, 29 Oct 2022 07:57:07 +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 7AE2C8869 for ; Sat, 29 Oct 2022 07:57:07 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooeU9-0002eo-Bl; Sat, 29 Oct 2022 01:34:21 -0400 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 1oodIV-0008Dk-9M for guix-patches@gnu.org; Sat, 29 Oct 2022 00:18:15 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oodIJ-0006rD-2A for guix-patches@gnu.org; Sat, 29 Oct 2022 00:18:14 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oodII-0005FO-Sk for guix-patches@gnu.org; Sat, 29 Oct 2022 00:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58855] [PATCH 2/5] services: mcron: Add log? and log-format fields to mcron-configuration. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 29 Oct 2022 04:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58855 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58855@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58855-submit@debbugs.gnu.org id=B58855.166701703320080 (code B ref 58855); Sat, 29 Oct 2022 04:18:02 +0000 Received: (at 58855) by debbugs.gnu.org; 29 Oct 2022 04:17:13 +0000 Received: from localhost ([127.0.0.1]:34740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oodHU-0005Dl-4C for submit@debbugs.gnu.org; Sat, 29 Oct 2022 00:17:12 -0400 Received: from mail-qt1-f177.google.com ([209.85.160.177]:43791) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oodHP-0005Cn-G5 for 58855@debbugs.gnu.org; Sat, 29 Oct 2022 00:17:08 -0400 Received: by mail-qt1-f177.google.com with SMTP id a27so1385108qtw.10 for <58855@debbugs.gnu.org>; Fri, 28 Oct 2022 21:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mfLfv0n5b4qfsecN3nfs5Ac9lGRa+9tMqTXsP6XusRE=; b=ccq1Opq/ECHz9/8ml1mccr6z0kY/iwhBrN8OXseSFbuumYR2QPovi6R7bB0iT+zbgg m37mF5u+Vli1JKOygGCLo1BjnoH4IgmGsMO6Dv0x5qqRQYHECTS7TN4SkdPBdOYjbkUQ QZJiMd1nBFayj6dfG2MohsOpSEDFnciJNRWsAR14yuOujJq7UzpaPuFt+Ry2zclEmyUL p9x40r4UkDzNY/sWdsXmCygLgCKrvssaslweJiR49AOVWrVp9kMELcPZWQYPe7H+/EEl A6PuDk8k5cFM68M5SwR4wofXetS8S2msQJ0YUYsJaVbFfZNqqCkc8f5DM3f0NMahIkAk 4Rmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mfLfv0n5b4qfsecN3nfs5Ac9lGRa+9tMqTXsP6XusRE=; b=ikyvVnlf8c5bKCEqS0UctFCiJO9GQDNZG8vzxGl2O3U7Xiv9+FqJUZaxq66g5NfZN4 EobyJ9ESOvK2AElMgITutRCYQxrG9Gl/a7fG7jARN0u/4HMwQsn/+YQyzgdCjI+pVpud tBsuFlNNm6lTB4bYbvKTgEVx8TRjoFtuBj/5YsEudMJCk/Tk5VM+zIjCpTteiR1CpqVE 9jzhRJGhccEQmL7gK+IuzBzx2yE1LIEEOA2JZtc1M7c7Mbn6X4D3+mVqU2k3EGN0muFt evOlKcry0nPlHR5Z4y2RUjhyVWRWgpmMwZ3BpVFhIR15IntaKB8GaVbvWokmx/Rskgap YyYw== X-Gm-Message-State: ACrzQf3oMTmyEzuPDbve3DKlLkW2WFAflOvAJT55cC+dcYFoVvscfHwP Dp5+9E9ZqRvy9pITA5EgTP7SWgnsjO8= X-Google-Smtp-Source: AMsMyM5gwUkF7yUY27Hku42A1b0i0k3iWQDWpSU3kPd7Og9dZ2wSFQGh7Fie2msqsEdi6MlQam8ALQ== X-Received: by 2002:a05:622a:13ce:b0:39c:c82a:4584 with SMTP id p14-20020a05622a13ce00b0039cc82a4584mr2340902qtk.150.1667017021711; Fri, 28 Oct 2022 21:17:01 -0700 (PDT) Received: from localhost.localdomain (dsl-152-179.b2b2c.ca. [66.158.152.179]) by smtp.gmail.com with ESMTPSA id do28-20020a05620a2b1c00b006f87d28ea3asm391514qkb.54.2022.10.28.21.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 21:17:01 -0700 (PDT) From: Maxim Cournoyer Date: Sat, 29 Oct 2022 00:16:46 -0400 Message-Id: <20221029041649.12144-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221029041649.12144-1-maxim.cournoyer@gmail.com> References: <20221029041649.12144-1-maxim.cournoyer@gmail.com> 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: , Sender: "Guix-patches" Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667023027; 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=ggxMAR6BCb96wzyoLpgCFg7tc9S9NCRGBO6MF/V+Xus=; b=RYjjlsEpI6vS6WlNn1LmxgFKGD0AcsSR9LVRJyE0qv+IUj6lGi0kkPMBabWRBDnW6pvklz VKhMItLr4SXhdl6aGOXA4DSxSSPMSYfrt2XWAv+dIp7LdfdxlBJ8EnKay6aoS3WxvV5eQN Cbgx5ODJuNP8Jqsdcp7zA7SyJZGJXehSHjkstvtb6b1oXds+PktAr3fMGrxNowYuBFgBZz K82OLcTggSNtXCPOGaDsVAAfEzc0ITYyjhFnh5RjFKR89+VxN8eV4UfZVKLjgAXNlaeeVr 75ihQN/AOp+EO4X1TcxOSGe8h9hHVZH4exjeF702n0ht30EyEWEUgpDVtz1ocw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667023027; a=rsa-sha256; cv=none; b=mUqBhbL/zXw8jKw/8CihTyw1oFnF2w+FIXSnMHarGyduKpu8dO72fxoiwEDYPmXk2By+1S od01iPvA/PdTzn1HVIvgt7ujfjboGntXMphd0ZW1Fxz1zQVtqpXGPUGp87Qv+TRcdtxRiO G7jQMIj/OOVdDiZupfM1QAYh6G1pSz6EHxJGNd8hYTBqSfNiu51PGAkVB2IQ3SSJjalcT9 JB6jO0J3WSaEMqxJbm4upFbQnYqDoJ7OCMRl9NRjGnabDMFFu6/iWtGW/WfOfb+IYqK1cI dCPOFPyXGd7K/SwRLNY/6heYaXW2327lv6WjTQ/R6ddyi/L/3V+uWEeOfrpBQg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="ccq1Opq/"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: 6.07 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="ccq1Opq/"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: 7AE2C8869 X-Spam-Score: 6.07 X-Migadu-Scanner: scn1.migadu.com X-TUID: B5Z7LPMudaVw * gnu/services/mcron.scm (list-of-gexps?): New predicate. (mcron-configuration): Rewrite using define-configuration. [log?, log-format]: New fields. (mcron-shepherd-services): Invoke mcron with the --log and --log-format arguments when log? is #t, (generate-doc): New procedure. * doc/guix.texi (Scheduled Job Execution): Update doc. (Mcron Home Service): Likewise. * gnu/home/services/mcron.scm: Keep in sync with the above changes to gnu/services/mcron.scm. --- doc/guix.texi | 45 ++++++++++++++++++++++++++++------- gnu/home/services/mcron.scm | 47 ++++++++++++++++++++++++++++--------- gnu/services/mcron.scm | 47 ++++++++++++++++++++++++++++--------- 3 files changed, 108 insertions(+), 31 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 80fb3bc47f..aadd16dd53 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -18994,20 +18994,33 @@ words, it is possible to define services that provide additional mcron jobs to run. @end defvr +@c Generated via (generate-documentation) at the bottom of (gnu services +@c mcron). +@c %start of fragment @deftp {Data Type} mcron-configuration -Data type representing the configuration of mcron. +Available @code{mcron-configuration} fields are: @table @asis -@item @code{mcron} (default: @var{mcron}) +@item @code{mcron} (default: @code{mcron}) (type: file-like) The mcron package to use. -@item @code{jobs} +@item @code{jobs} (default: @code{()}) (type: list-of-gexps) This is a list of gexps (@pxref{G-Expressions}), where each gexp corresponds to an mcron job specification (@pxref{Syntax, mcron job -specifications,, mcron, GNU@tie{}mcron}). +specifications,, mcron,GNU@tie{}mcron}). + +@item @code{log?} (default: @code{#t}) (type: boolean) +Log messages to standard output. + +@item @code{log-format} (default: @code{"~1@@*~a ~a: ~a~%"}) (type: string) +@code{(ice-9 format)} format string for log messages. The default value +produces messages like "@samp{@var{pid} @var{name}: @var{message}"} +(@pxref{Invoking mcron, Invoking,, mcron,GNU@tie{}mcron}). Each message +is also prefixed by a timestamp by GNU Shepherd. + @end table @end deftp - +@c %end of fragment @node Log Rotation @subsection Log Rotation @@ -41015,18 +41028,32 @@ jobs to run. @end defvr @deftp {Data Type} home-mcron-configuration -Data type representing the configuration of mcron. +Available @code{home-mcron-configuration} fields are: +@c Auto-generated with (gnu home services mcron)'s +@c generate-documentation procedure. +@c %start of fragment @table @asis -@item @code{mcron} (default: @var{mcron}) +@item @code{mcron} (default: @code{mcron}) (type: file-like) The mcron package to use. -@item @code{jobs} +@item @code{jobs} (default: @code{()}) (type: list-of-gexps) This is a list of gexps (@pxref{G-Expressions}), where each gexp corresponds to an mcron job specification (@pxref{Syntax, mcron job -specifications,, mcron, GNU@tie{}mcron}). +specifications,, mcron,GNU@tie{}mcron}). + +@item @code{log?} (default: @code{#t}) (type: boolean) +Log messages to standard output. + +@item @code{log-format} (default: @code{"~1@@*~a ~a: ~a~%"}) (type: string) +@code{(ice-9 format)} format string for log messages. The default value +produces messages like "@samp{@var{pid} @var{name}: @var{message}"} +(@pxref{Invoking mcron, Invoking,, mcron,GNU@tie{}mcron}). Each message +is also prefixed by a timestamp by GNU Shepherd. + @end table @end deftp +@c %end of fragment @node Power Management Home Services @subsection Power Management Home Services diff --git a/gnu/home/services/mcron.scm b/gnu/home/services/mcron.scm index 0b3dbb810b..1d294a997c 100644 --- a/gnu/home/services/mcron.scm +++ b/gnu/home/services/mcron.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,6 +21,7 @@ (define-module (gnu home services mcron) #:use-module (gnu packages guile-xyz) #:use-module (gnu home services) + #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:use-module (gnu home services shepherd) #:use-module (guix records) @@ -53,13 +55,23 @@ (define-module (gnu home services mcron) ;; ;;; Code: -(define-record-type* home-mcron-configuration - make-home-mcron-configuration - home-mcron-configuration? - (package home-mcron-configuration-package ; package - (default mcron)) - (jobs home-mcron-configuration-jobs ; list of jobs - (default '()))) +(define list-of-gexps? + (list-of gexp?)) + +(define-configuration/no-serialization home-mcron-configuration + (mcron (file-like mcron) "The mcron package to use.") + (jobs + (list-of-gexps '()) + "This is a list of gexps (@pxref{G-Expressions}), where each gexp +corresponds to an mcron job specification (@pxref{Syntax, mcron job +specifications,, mcron, GNU@tie{}mcron}).") + (log? (boolean #t) "Log messages to standard output.") + (log-format + (string "~1@*~a ~a: ~a~%") + "@code{(ice-9 format)} format string for log messages. The default value +produces messages like \"@samp{@var{pid} @var{name}: +@var{message}\"} (@pxref{Invoking mcron, Invoking,, mcron, GNU@tie{}mcron}). +Each message is also prefixed by a timestamp by GNU Shepherd.")) (define job-files (@@ (gnu services mcron) job-files)) (define shepherd-schedule-action @@ -69,19 +81,23 @@ (define home-mcron-shepherd-services (match-lambda (($ mcron '()) ; no jobs to run '()) - (($ mcron jobs) + (($ mcron jobs log? log-format) (let ((files (job-files mcron jobs))) (list (shepherd-service (documentation "User cron jobs.") (provision '(mcron)) (modules `((srfi srfi-1) (srfi srfi-26) - (ice-9 popen) ; for the 'schedule' action + (ice-9 popen) ; for the 'schedule' action (ice-9 rdelim) (ice-9 match) ,@%default-modules)) (start #~(make-forkexec-constructor - (list #$(file-append mcron "/bin/mcron") #$@files) + (list (string-append #$mcron "/bin/mcron") + #$@(if log? + #~("--log" "--log-format" #$log-format) + #~()) + #$@files) #:log-file (string-append (or (getenv "XDG_LOG_HOME") (format #f "~a/.local/var/log" @@ -91,7 +107,7 @@ (define home-mcron-shepherd-services (actions (list (shepherd-schedule-action mcron files))))))))) -(define home-mcron-profile (compose list home-mcron-configuration-package)) +(define home-mcron-profile (compose list home-mcron-configuration-mcron)) (define (home-mcron-extend config jobs) (home-mcron-configuration @@ -113,3 +129,12 @@ (define home-mcron-service-type (default-value (home-mcron-configuration)) (description "Install and configure the GNU mcron cron job manager."))) + + +;;; +;;; Generate documentation. +;;; +(define (generate-doc) + (configuration->documentation 'home-mcron-configuration)) + +;;; mcron.scm ends here diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm index 23760ebda4..52332d6123 100644 --- a/gnu/services/mcron.scm +++ b/gnu/services/mcron.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2022 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,6 +19,7 @@ (define-module (gnu services mcron) #:use-module (gnu services) + #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:use-module (gnu packages guile-xyz) #:use-module (guix deprecation) @@ -30,6 +32,8 @@ (define-module (gnu services mcron) mcron-configuration? mcron-configuration-mcron mcron-configuration-jobs + mcron-configuration-log? + mcron-configuration-log-format mcron-service-type)) @@ -48,13 +52,23 @@ (define-module (gnu services mcron) ;;; ;;; Code: -(define-record-type* mcron-configuration - make-mcron-configuration - mcron-configuration? - (mcron mcron-configuration-mcron ;file-like - (default mcron)) - (jobs mcron-configuration-jobs ;list of - (default '()))) +(define list-of-gexps? + (list-of gexp?)) + +(define-configuration/no-serialization mcron-configuration + (mcron (file-like mcron) "The mcron package to use.") + (jobs + (list-of-gexps '()) + "This is a list of gexps (@pxref{G-Expressions}), where each gexp +corresponds to an mcron job specification (@pxref{Syntax, mcron job +specifications,, mcron, GNU@tie{}mcron}).") + (log? (boolean #t) "Log messages to standard output.") + (log-format + (string "~1@*~a ~a: ~a~%") + "@code{(ice-9 format)} format string for log messages. The default value +produces messages like \"@samp{@var{pid} @var{name}: +@var{message}\"} (@pxref{Invoking mcron, Invoking,, mcron, GNU@tie{}mcron}). +Each message is also prefixed by a timestamp by GNU Shepherd.")) (define (job-files mcron jobs) "Return a list of file-like object for JOBS, a list of gexps." @@ -124,21 +138,25 @@ (define (shepherd-schedule-action mcron files) (define mcron-shepherd-services (match-lambda - (($ mcron ()) ;nothing to do! + (($ mcron ()) ;nothing to do! '()) - (($ mcron jobs) + (($ mcron jobs log? log-format) (let ((files (job-files mcron jobs))) (list (shepherd-service (provision '(mcron)) (requirement '(user-processes)) (modules `((srfi srfi-1) (srfi srfi-26) - (ice-9 popen) ;for the 'schedule' action + (ice-9 popen) ;for the 'schedule' action (ice-9 rdelim) (ice-9 match) ,@%default-modules)) (start #~(make-forkexec-constructor - (list (string-append #$mcron "/bin/mcron") #$@files) + (list (string-append #$mcron "/bin/mcron") + #$@(if log? + #~("--log" "--log-format" #$log-format) + #~()) + #$@files) ;; Disable auto-compilation of the job files and set a ;; sane value for 'PATH'. @@ -172,4 +190,11 @@ (define mcron-service-type jobs))))) (default-value (mcron-configuration)))) ;empty job list + +;;; +;;; Generate documentation. +;;; +(define (generate-doc) + (configuration->documentation 'mcron-configuration)) + ;;; mcron.scm ends here -- 2.37.3