unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#62465] [PATCH] services: mcron: Add instance name support for mcron.
@ 2023-03-26 18:18 Bruno Victal
  2023-03-29 13:44 ` [bug#62465] [PATCH v2 1/2] services: mcron: Add 'shepherd-requirement' field Bruno Victal
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Bruno Victal @ 2023-03-26 18:18 UTC (permalink / raw)
  To: 62465; +Cc: Bruno Victal, maxim.cournoyer

Allow running more than one mcron instance.

Follow-up to <https://issues.guix.gnu.org/62169>.

* 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-configuration>
-    (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)
-- 
2.39.1





^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-01 17:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-26 18:18 [bug#62465] [PATCH] services: mcron: Add instance name support for mcron Bruno Victal
2023-03-29 13:44 ` [bug#62465] [PATCH v2 1/2] services: mcron: Add 'shepherd-requirement' field Bruno Victal
2023-03-29 13:54   ` [bug#62465] [PATCH v2 2/2] services: mcron: Add instance name support for mcron Bruno Victal
2023-03-30 14:15 ` [bug#62465] [PATCH v3 1/2] services: mcron: Add 'shepherd-requirement' field Bruno Victal
2023-03-30 14:15   ` [bug#62465] [PATCH v3 2/2] services: mcron: Add instance name support for mcron Bruno Victal
2023-04-01 17:35 ` [bug#62465] [PATCH v4 1/3] services: mcron: Add 'shepherd-requirement' field Bruno Victal
2023-04-01 17:35   ` [bug#62465] [PATCH v4 2/3] services: mcron: Add instance name support for mcron Bruno Victal
2023-04-01 17:35   ` [bug#62465] [PATCH v4 3/3] services: mcron: Add user-name, user-group and supplementary-groups fields Bruno Victal

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).