From patchwork Sun Mar 26 18:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Victal X-Patchwork-Id: 48712 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1FA8D1700A; Sun, 26 Mar 2023 19:19:24 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 02D4116934 for ; Sun, 26 Mar 2023 19:19:21 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgUxM-00031F-7t; Sun, 26 Mar 2023 14:19:04 -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 1pgUxL-000316-6O for guix-patches@gnu.org; Sun, 26 Mar 2023 14:19:03 -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 1pgUxK-0006Jd-LH for guix-patches@gnu.org; Sun, 26 Mar 2023 14:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pgUxK-0002Zh-8n; Sun, 26 Mar 2023 14:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62465] [PATCH] services: mcron: Add instance name support for mcron. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 26 Mar 2023 18:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62465 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62465@debbugs.gnu.org Cc: Bruno Victal , maxim.cournoyer@gmail.com X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: maxim.cournoyer@gmail.com Received: via spool by submit@debbugs.gnu.org id=B.16798547269873 (code B ref -1); Sun, 26 Mar 2023 18:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Mar 2023 18:18:46 +0000 Received: from localhost ([127.0.0.1]:45776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgUx3-0002ZB-RZ for submit@debbugs.gnu.org; Sun, 26 Mar 2023 14:18:46 -0400 Received: from lists.gnu.org ([209.51.188.17]:50520) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgUx2-0002Z1-Bs for submit@debbugs.gnu.org; Sun, 26 Mar 2023 14:18:44 -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 1pgUx1-0002yT-Va for guix-patches@gnu.org; Sun, 26 Mar 2023 14:18:43 -0400 Received: from smtpm1.myservices.hosting ([185.26.105.232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pgUwz-0006HT-Tk for guix-patches@gnu.org; Sun, 26 Mar 2023 14:18:43 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpm1.myservices.hosting (Postfix) with ESMTP id B74CA202E5 for ; Sun, 26 Mar 2023 20:18:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 52D3F800A9; Sun, 26 Mar 2023 20:18:39 +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 4y3TgJg0ssaJ; Sun, 26 Mar 2023 20:18:38 +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 E5E91800A8; Sun, 26 Mar 2023 20:18:37 +0200 (CEST) From: Bruno Victal Date: Sun, 26 Mar 2023 19:18:25 +0100 Message-Id: <47e924fd42f74fc2800dc64399f7a069ad463515.1679854500.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Received-SPF: pass client-ip=185.26.105.232; envelope-from=mirai@makinata.eu; helo=smtpm1.myservices.hosting X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Allow running more than one mcron instance. Follow-up to . * gnu/services/mcron.scm (mcron-configuration)[instance-name]: New field. (shepherd-schedule-action): Implement instance-name support. * doc/guix.texi (Scheduled Job Execution): Update it. --- doc/guix.texi | 26 ++++++++++++++++++++++++++ gnu/services/mcron.scm | 16 +++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 3e335306f1..0f735489d5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19376,6 +19376,10 @@ Scheduled Job Execution @item @code{mcron} (default: @code{mcron}) (type: file-like) The mcron package to use. +@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 @@ -19400,6 +19404,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 2ef5980e09..c949f1aebc 100644 --- a/gnu/services/mcron.scm +++ b/gnu/services/mcron.scm @@ -27,6 +27,7 @@ (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 @@ -59,12 +60,18 @@ (define list-of-gexps? (list-of gexp?)) (define-maybe/no-serialization string) +(define-maybe/no-serialization symbol) (define-configuration/no-serialization mcron-configuration (mcron (file-like mcron) "The mcron package to use.") + (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 @@ -158,12 +165,15 @@ (define (shepherd-schedule-action mcron files) (define (mcron-shepherd-services config) (match-record config - (mcron jobs log? log-file log-format date-format) + (mcron jobs log? log-file log-format date-format instance) (if (eq? jobs '()) '() ;nothing to do - (let ((files (job-files mcron jobs))) + (let ((files (job-files mcron jobs)) + (service-name + (string->symbol + (format #f "mcron~@[-~a~]" (maybe-value instance))))) (list (shepherd-service - (provision '(mcron)) + (provision (list service-name)) (requirement '(user-processes)) (modules `((srfi srfi-1) (srfi srfi-26)