From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 0GS3Ew1sKGS/fgEASxT56A (envelope-from ) for ; Sat, 01 Apr 2023 19:38:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id uKPCEw1sKGS3LgAAauVa8A (envelope-from ) for ; Sat, 01 Apr 2023 19:38:21 +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 DCEE53A25A for ; Sat, 1 Apr 2023 19:38:20 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pifB3-0003AQ-AI; Sat, 01 Apr 2023 13:38:09 -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 1pifB2-0003A4-4d for guix-patches@gnu.org; Sat, 01 Apr 2023 13:38:08 -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 1pifAw-0006n3-Kp for guix-patches@gnu.org; Sat, 01 Apr 2023 13:38:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pifAw-00012U-3i for guix-patches@gnu.org; Sat, 01 Apr 2023 13:38:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62465] [PATCH v4 2/3] services: mcron: Add instance name support for mcron. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 01 Apr 2023 17:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62465 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62465@debbugs.gnu.org Cc: Bruno Victal , maxim.cournoyer@gmail.com Received: via spool by 62465-submit@debbugs.gnu.org id=B62465.16803706403942 (code B ref 62465); Sat, 01 Apr 2023 17:38:02 +0000 Received: (at 62465) by debbugs.gnu.org; 1 Apr 2023 17:37:20 +0000 Received: from localhost ([127.0.0.1]:38544 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pifAG-00011V-0F for submit@debbugs.gnu.org; Sat, 01 Apr 2023 13:37:20 -0400 Received: from smtpmciv1.myservices.hosting ([185.26.107.237]:47650) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pifAE-00011N-BO for 62465@debbugs.gnu.org; Sat, 01 Apr 2023 13:37:19 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpmciv1.myservices.hosting (Postfix) with ESMTP id 7C0A720D4B; Sat, 1 Apr 2023 19:37:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 20D4A8009D; Sat, 1 Apr 2023 19:37:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id G7hG83HLpm6z; Sat, 1 Apr 2023 19:37:16 +0200 (CEST) Received: from guix-nuc.home.arpa (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 4A28F8009B; Sat, 1 Apr 2023 19:37:16 +0200 (CEST) From: Bruno Victal Date: Sat, 1 Apr 2023 18:35:54 +0100 Message-Id: <32221c49b24430902cbd0b7881a26e8a813ec871.1680370145.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 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-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1680370701; a=rsa-sha256; cv=none; b=R6B9xq1vIUoHs2azYaPgBjKPSG/NHyxVxR+ubjTfFg8AHrQr+LD7O3mWWUmxOlUl/M532N Z3q9f0IlYflqtUd0drZJBJKpbn27Cd4L02w/rAflWus/6Nl7RgPcq7Z0XoN8LkFG8uWS59 PpO+PFJMa0fqEyq8GfN7bKXkVkPKJzK2TjIXmubSlz4s4CE+twbq7d6ttm1F911I7Xdfxo 5B4H3iBS/bItLBZ50+pr+e2x95DoRJ5X2alrDNeiGGqeM+tQ0c5OnY50vFg7OzS+XQFbcS 75ZYvsxnlUEHU+YE9w2MJf68jt4fM634I/hpRVB9p/J3UxeLsmnZMtuwMvNPlA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1680370701; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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; bh=a8MIHmKKPwe/O3nl+YYLTQI38M7xFeKTfG66dzW/WEU=; b=dISsfFwd9Vk2zonA6GzAavoaZwaHGltvrHjdmE+aw5UVUF7IQXx863HhVXlqJ5EWzoYsUC 84JDl4AleQCSFp72QnRJf4Fd97H0uXq+jil7Oq31JwLqxFzye7xt8sFdQqPLTeoybs8+j0 PevgKBhssnVD3gu6gbQrUIdhN4Tv7a0RP503q3GkMjqww/C/ePefM11BsvaLmUZpy/A4HA RG54ram7XtpJGGfmUR6idj3MJNLlDTm47pmwK3/kyRLQ8hGDau0aPhURoqpBwN8oAP/vs8 gdhcaXW2K5IPfUvX6frj4qeAUSc1LfTBnqi5KjdXp5Zf74pGO6PhzwajE10Tgg== X-Migadu-Spam-Score: -1.73 X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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-Spam-Score: -1.73 X-Migadu-Queue-Id: DCEE53A25A X-TUID: WCGW4e1vAxBI Allow running more than one mcron instance. Make log-file a mandatory field when instantiating mcron-configuration records. Follow-up to . * gnu/services/mcron.scm (mcron-configuration)[instance-name]: New field. [log-file]: Update description. Remove default value. (mcron-shepherd-services): Implement instance-name support. Set the default service instantiation to log to /var/log/mcron.log. * gnu/tests/base.scm (%mcron-os): Update tests. * doc/guix.texi (Scheduled Job Execution): Update it. --- doc/guix.texi | 32 ++++++++++++++++++++++++++++++-- gnu/services/mcron.scm | 28 ++++++++++++++++++++++------ gnu/tests/base.scm | 4 +++- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 56aa86118a..e2781cb439 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19383,6 +19383,10 @@ Scheduled Job Execution This is a list of symbols naming Shepherd services that this service will depend on. +@item @code{instance} (type: maybe-symbol) +Set the shepherd service name to @code{mcron-@var{instance}}. This is +useful when you want to have more than one mcron instance. + @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 @@ -19391,8 +19395,10 @@ Scheduled Job Execution @item @code{log?} (default: @code{#t}) (type: boolean) Log messages to standard output. -@item @code{log-file} (default: @code{"/var/log/mcron.log"}) (type: string) -Log file location. +@item @code{log-file} (type: string) +Log file location. By default, the main mcron instance (which is +instantiated with @samp{(service mcron-service-type)}) is set to log to +@file{/var/log/mcron.log}. @item @code{log-format} (default: @code{"~1@@*~a ~a: ~a~%"}) (type: string) @code{(ice-9 format)} format string for log messages. The default value @@ -19407,6 +19413,28 @@ Scheduled Job Execution @end deftp @c %end of fragment +Occasionally, it is desirable to run another mcron instance to separate +some of the jobs from the main mcron instance for clarity purposes, or if +the jobs are very chatty and frequent. (for example, a heartbeat check +every 30 seconds) + +The example below shows how an extra mcron service can be defined. +@lisp +(use (guix) + (guix records) + (gnu services) + (gnu services mcron)) + +(define secondary-mcron-service-type + (service-type + (inherit mcron-service-type) + (name 'mcron-secondary) + (default-value + (mcron-configuration + (instance 'secondary) + (log-file "/var/log/mcron-secondary.log"))))) +@end lisp + @node Log Rotation @subsection Log Rotation diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm index 99eb0edd60..164ef0e723 100644 --- a/gnu/services/mcron.scm +++ b/gnu/services/mcron.scm @@ -27,12 +27,14 @@ (define-module (gnu services mcron) #:use-module (guix records) #:use-module (guix gexp) #:use-module (srfi srfi-1) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 vlist) #:export (mcron-configuration mcron-configuration? mcron-configuration-mcron mcron-configuration-shepherd-requirement + mcron-configuration-instance mcron-configuration-jobs mcron-configuration-log? mcron-configuration-log-file @@ -63,6 +65,7 @@ (define list-of-symbols? (list-of symbol?)) (define-maybe/no-serialization string) +(define-maybe/no-serialization symbol) (define-configuration/no-serialization mcron-configuration (mcron @@ -74,6 +77,11 @@ (define-configuration/no-serialization mcron-configuration "This is a list of symbols naming Shepherd services that this service will depend on.") + (instance + maybe-symbol + "Set the shepherd service name to @code{mcron-@var{instance}}. +This is useful when you want to have more than one mcron instance.") + (jobs (list-of-gexps '()) "This is a list of gexps (@pxref{G-Expressions}), where each gexp @@ -85,8 +93,10 @@ (define-configuration/no-serialization mcron-configuration "Log messages to standard output.") (log-file - (string "/var/log/mcron.log") - "Log file location.") + string + "Log file location. By default, the main mcron instance +(which is instantiated with @samp{(service mcron-service-type)}) +is set to log to @file{/var/log/mcron.log}.") (log-format (string "~1@*~a ~a: ~a~%") @@ -167,12 +177,16 @@ (define (shepherd-schedule-action mcron files) (define (mcron-shepherd-services config) (match-record config - (mcron shepherd-requirement jobs log? log-file log-format date-format) + (mcron shepherd-requirement instance + jobs log? log-file log-format date-format) (if (eq? jobs '()) '() ;nothing to do - (let ((files (job-files mcron jobs))) + (let* ((files (job-files mcron jobs)) + (instance-name + (format #f "mcron~@[-~a~]" (maybe-value instance))) + (service-name (string->symbol instance-name))) (list (shepherd-service - (provision '(mcron)) + (provision (list service-name)) (requirement `(user-processes ,@shepherd-requirement)) (modules `((srfi srfi-1) (srfi srfi-26) @@ -220,7 +234,9 @@ (define mcron-service-type (inherit config) (jobs (append (mcron-configuration-jobs config) jobs))))) - (default-value (mcron-configuration)))) ;empty job list + (default-value + (mcron-configuration + (log-file "/var/log/mcron.log"))))) ;empty job list ;;; diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm index 97edbbc6ad..ffff713e4c 100644 --- a/gnu/tests/base.scm +++ b/gnu/tests/base.scm @@ -885,7 +885,9 @@ (define %mcron-os "touch witness-touch"))) (simple-operating-system (service mcron-service-type - (mcron-configuration (jobs (list job1 job2 job3))))))) + (mcron-configuration + (jobs (list job1 job2 job3)) + (log-file "/var/log/mcron.log")))))) (define (run-mcron-test name) (define os -- 2.39.1