From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id wN1TO0ZDJGSgQAAASxT56A (envelope-from ) for ; Wed, 29 Mar 2023 15:55:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id AKPlOkZDJGQNWgEAauVa8A (envelope-from ) for ; Wed, 29 Mar 2023 15:55:18 +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 25AA347CEE for ; Wed, 29 Mar 2023 15:55:17 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phWGf-0002eM-90; Wed, 29 Mar 2023 09:55:13 -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 1phWGU-0002co-JI for guix-patches@gnu.org; Wed, 29 Mar 2023 09:55:05 -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 1phWGU-0000Nn-BU for guix-patches@gnu.org; Wed, 29 Mar 2023 09:55:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1phWGT-0000ai-OE for guix-patches@gnu.org; Wed, 29 Mar 2023 09:55:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62465] [PATCH v2 2/2] services: mcron: Add instance name support for mcron. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 29 Mar 2023 13:55:01 +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.16800980862242 (code B ref 62465); Wed, 29 Mar 2023 13:55:01 +0000 Received: (at 62465) by debbugs.gnu.org; 29 Mar 2023 13:54:46 +0000 Received: from localhost ([127.0.0.1]:51554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phWGD-0000a6-KS for submit@debbugs.gnu.org; Wed, 29 Mar 2023 09:54:46 -0400 Received: from smtpmciv3.myservices.hosting ([185.26.107.239]:38036) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phWGB-0000Zy-U7 for 62465@debbugs.gnu.org; Wed, 29 Mar 2023 09:54:44 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpmciv3.myservices.hosting (Postfix) with ESMTP id C8F062038A; Wed, 29 Mar 2023 15:54:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 64AC080079; Wed, 29 Mar 2023 15:54:42 +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 d_nZwT1_pIW1; Wed, 29 Mar 2023 15:54:42 +0200 (CEST) Received: from guix-nuc.home.arpa (bl9-119-177.dsl.telepac.pt [85.242.119.177]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 7E6E98009A; Wed, 29 Mar 2023 15:54:41 +0200 (CEST) From: Bruno Victal Date: Wed, 29 Mar 2023 14:54:34 +0100 Message-Id: <79a56d4be6ad19853bbae7dd3e6767b5b78806c2.1680098053.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: <26ad3fb85ba517dc1a500c287f07f20a00cec625.1680097409.git.mirai@makinata.eu> References: <26ad3fb85ba517dc1a500c287f07f20a00cec625.1680097409.git.mirai@makinata.eu> 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-Flow: FLOW_IN X-Migadu-Country: US ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1680098118; 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=R3IYyoOaQqYTy5VgSbncHK9DEkXl6t/Q3OwD7Gumbeg=; b=QS3FBGQgHqcIO2imLvOqxqhkyKtHpmo+0Z4vYxL1xf96/1Kjr6+aeIfXEERdv1ug8Kq5XS V1v6gN4n2f17E01Dmm3cS6jLwj5G8k0qMNtWEMq3FE2lfH+JrPeEw3H2UyTGK4xun8v5oL zWHdi39xINxYiXhlEjhAm34TmtUNiDG3Cpd3lncR1bm/QTTCM8Y7AfJeFoZS/R1kS4r/t7 pdo2AbzyUA6DkwG1hfR+O//inBlAWJSH+n8ON3VWPQZwhpCfWtLx3LCY7JkVJEDJsaJX7w L2YAoZ99CU3UTBriQQ7DuzHmA3x8Q/UW/EkjxsM8acPMddG59l/kADGrU/4+0A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1680098118; a=rsa-sha256; cv=none; b=J3TLPsQaIVxgLh4xTFK73yL0m5ufNU8ciFopSBE45M55UB22H2vrysFhfagQwN7ojQjMIi 1IMoC6tFih83G9UBXpwiu67/eBxxy9Lh8sszq5AAOkNfJUYjfCbPtj2pwIp8dzzLVsu2TZ 7cvGlPAI8maBQvnryzg5TBJcr1n03ZEayKYyjyyY/zkd1aIiMSx6azPVsWa2uy9sp/+qyW e2vqblqlPnHqVSF1C4P08ZEskJTgVSdb3sBo7lq90uo0kdXat/BZ+J86cyowsIn8dhFPrG Q3bEvZZNaZ572v7tZ2ih5nWsYrM16H8u4dUxZL08ZbEEnA2qQ+Tam/3bIbmO4A== X-Migadu-Spam-Score: -0.23 X-Migadu-Scanner: scn1.migadu.com X-Migadu-Queue-Id: 25AA347CEE Authentication-Results: aspmx1.migadu.com; dkim=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"; dmarc=none X-Spam-Score: -0.23 X-TUID: iv0r0wqQLGkI Allow running more than one mcron instance. Make log-file robust against operator error when provisioning an additional mcron instance but log-file is left at its default value. Follow-up to . * gnu/services/mcron.scm (mcron-configuration)[instance-name]: New field. [log-file]: Update description. (mcron-shepherd-services): Implement instance-name support. Make log-file robust against multiple instances writing to the same default log-file. * doc/guix.texi (Scheduled Job Execution): Update it. --- doc/guix.texi | 30 +++++++++++++++++++++++++++++- gnu/services/mcron.scm | 34 +++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5a597cf122..ba80b9660c 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 @@ -19392,7 +19396,9 @@ Scheduled Job Execution Log messages to standard output. @item @code{log-file} (default: @code{"/var/log/mcron.log"}) (type: string) -Log file location. +Log file location. When @var{instance} is set and @var{log-file} is +kept at its @emph{default value}, it will log to +@file{/var/log/mcron-@var{instance}.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..4d8ab4af2c 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 @@ -86,7 +94,9 @@ (define-configuration/no-serialization mcron-configuration (log-file (string "/var/log/mcron.log") - "Log file location.") + "Log file location. When @var{instance} is set and @var{log-file} +is kept at its @emph{default value}, it will log to +@file{/var/log/mcron-@var{instance}.log}.") (log-format (string "~1@*~a ~a: ~a~%") @@ -167,12 +177,26 @@ (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)) + ;; Make log-file robust against multiple instances + ;; attempting to write to the same file when + ;; left at its default value. + (default-log-file (mcron-configuration-log-file + (mcron-configuration))) + (log-file* (if (and (maybe-value-set? instance) + (equal? log-file default-log-file)) + (string-append (dirname default-log-file) + "/" instance-name ".log") + log-file))) (list (shepherd-service - (provision '(mcron)) + (provision (list service-name)) (requirement `(user-processes ,@shepherd-requirement)) (modules `((srfi srfi-1) (srfi srfi-26) @@ -199,7 +223,7 @@ (define (mcron-shepherd-services config) (remove (cut string-prefix? "PATH=" <>) (environ))) - #:log-file #$log-file)) + #:log-file #$log-file*)) (stop #~(make-kill-destructor)) (actions (list (shepherd-schedule-action mcron files))))))))) -- 2.39.1