GNU bug report logs - #62465
[PATCH] services: mcron: Add instance name support for mcron.

Previous Next

Package: guix-patches;

Reported by: Bruno Victal <mirai <at> makinata.eu>

Date: Sun, 26 Mar 2023 18:19:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 62465 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Sun, 26 Mar 2023 18:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bruno Victal <mirai <at> makinata.eu>:
New bug report received and forwarded. Copy sent to maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org. (Sun, 26 Mar 2023 18:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: guix-patches <at> gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>
Subject: [PATCH] services: mcron: Add instance name support for mcron.
Date: Sun, 26 Mar 2023 19:18:25 +0100
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





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Wed, 29 Mar 2023 13:50:02 GMT) Full text and rfc822 format available.

Message #8 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v2 1/2] services: mcron: Add 'shepherd-requirement' field.
Date: Wed, 29 Mar 2023 14:44:05 +0100
* gnu/services/mcron.scm (mcron-configuration)[shepherd-requirement]: New field.
(list-of-symbols?): New predicate.
(mcron-shepherd-services): Add support for additional shepherd requirements.
* doc/guix.texi (Scheduled Job Execution): Update it.
---
 doc/guix.texi          |  4 ++++
 gnu/services/mcron.scm | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c49e51b72e..5a597cf122 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19379,6 +19379,10 @@ Scheduled Job Execution
 @item @code{mcron} (default: @code{mcron}) (type: file-like)
 The mcron package to use.
 
+@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbols)
+This is a list of symbols naming Shepherd services that this service
+will depend on.
+
 @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
diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm
index 2ef5980e09..99eb0edd60 100644
--- a/gnu/services/mcron.scm
+++ b/gnu/services/mcron.scm
@@ -32,6 +32,7 @@ (define-module (gnu services mcron)
   #:export (mcron-configuration
             mcron-configuration?
             mcron-configuration-mcron
+            mcron-configuration-shepherd-requirement
             mcron-configuration-jobs
             mcron-configuration-log?
             mcron-configuration-log-file
@@ -58,6 +59,9 @@ (define-module (gnu services mcron)
 (define list-of-gexps?
   (list-of gexp?))
 
+(define list-of-symbols?
+  (list-of symbol?))
+
 (define-maybe/no-serialization string)
 
 (define-configuration/no-serialization mcron-configuration
@@ -65,6 +69,11 @@ (define-configuration/no-serialization mcron-configuration
    (file-like mcron)
    "The mcron package to use.")
 
+  (shepherd-requirement
+   (list-of-symbols '())
+   "This is a list of symbols naming Shepherd services that this service
+will depend on.")
+
   (jobs
    (list-of-gexps '())
    "This is a list of gexps (@pxref{G-Expressions}), where each gexp
@@ -158,13 +167,13 @@ (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 shepherd-requirement jobs log? log-file log-format date-format)
     (if (eq? jobs '())
         '()                             ;nothing to do
         (let ((files (job-files mcron jobs)))
           (list (shepherd-service
                  (provision '(mcron))
-                 (requirement '(user-processes))
+                 (requirement `(user-processes ,@shepherd-requirement))
                  (modules `((srfi srfi-1)
                             (srfi srfi-26)
                             (ice-9 popen) ;for the 'schedule' action
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Wed, 29 Mar 2023 13:55:01 GMT) Full text and rfc822 format available.

Message #11 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v2 2/2] services: mcron: Add instance name support for mcron.
Date: Wed, 29 Mar 2023 14:54:34 +0100
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 <https://issues.guix.gnu.org/62169>.

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





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Thu, 30 Mar 2023 14:16:02 GMT) Full text and rfc822 format available.

Message #14 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v3 1/2] services: mcron: Add 'shepherd-requirement' field.
Date: Thu, 30 Mar 2023 15:15:18 +0100
* gnu/services/mcron.scm (mcron-configuration)[shepherd-requirement]: New field.
(list-of-symbols?): New predicate.
(mcron-shepherd-services): Add support for additional shepherd requirements.
* doc/guix.texi (Scheduled Job Execution): Update it.
---

Notable changes from v2 to v3:
  Changing the final log-file value used in v2 behind the scenes
made it poorly reflexive as you couldn't trust what the accessors returned.
v3 makes log-file a mandatory field that has to be set manually and leaves
the default service instantiation responsible for setting the default log-file
that is used for the main mcron instance.

 doc/guix.texi          |  4 ++++
 gnu/services/mcron.scm | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c49e51b72e..5a597cf122 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19379,6 +19379,10 @@ Scheduled Job Execution
 @item @code{mcron} (default: @code{mcron}) (type: file-like)
 The mcron package to use.
 
+@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbols)
+This is a list of symbols naming Shepherd services that this service
+will depend on.
+
 @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
diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm
index 2ef5980e09..99eb0edd60 100644
--- a/gnu/services/mcron.scm
+++ b/gnu/services/mcron.scm
@@ -32,6 +32,7 @@ (define-module (gnu services mcron)
   #:export (mcron-configuration
             mcron-configuration?
             mcron-configuration-mcron
+            mcron-configuration-shepherd-requirement
             mcron-configuration-jobs
             mcron-configuration-log?
             mcron-configuration-log-file
@@ -58,6 +59,9 @@ (define-module (gnu services mcron)
 (define list-of-gexps?
   (list-of gexp?))
 
+(define list-of-symbols?
+  (list-of symbol?))
+
 (define-maybe/no-serialization string)
 
 (define-configuration/no-serialization mcron-configuration
@@ -65,6 +69,11 @@ (define-configuration/no-serialization mcron-configuration
    (file-like mcron)
    "The mcron package to use.")
 
+  (shepherd-requirement
+   (list-of-symbols '())
+   "This is a list of symbols naming Shepherd services that this service
+will depend on.")
+
   (jobs
    (list-of-gexps '())
    "This is a list of gexps (@pxref{G-Expressions}), where each gexp
@@ -158,13 +167,13 @@ (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 shepherd-requirement jobs log? log-file log-format date-format)
     (if (eq? jobs '())
         '()                             ;nothing to do
         (let ((files (job-files mcron jobs)))
           (list (shepherd-service
                  (provision '(mcron))
-                 (requirement '(user-processes))
+                 (requirement `(user-processes ,@shepherd-requirement))
                  (modules `((srfi srfi-1)
                             (srfi srfi-26)
                             (ice-9 popen) ;for the 'schedule' action
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Thu, 30 Mar 2023 14:35:01 GMT) Full text and rfc822 format available.

Message #17 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v3 2/2] services: mcron: Add instance name support for mcron.
Date: Thu, 30 Mar 2023 15:15:19 +0100
Allow running more than one mcron instance.
Make log-file a mandatory field when instantiating
mcron-configuration records.

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

* 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.
---

Notable changes from v2 to v3:
  Changing the final log-file value used in v2 behind the scenes
made it poorly reflexive as you couldn't trust what the accessors returned.
v3 makes log-file a mandatory field that has to be set manually and leaves
the default service instantiation responsible for setting the default log-file
that is used for the main mcron instance.

 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 5a597cf122..b9bd78f3cc 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-configuration>
-    (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





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Sat, 01 Apr 2023 17:37:01 GMT) Full text and rfc822 format available.

Message #20 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v4 1/3] services: mcron: Add 'shepherd-requirement' field.
Date: Sat,  1 Apr 2023 18:35:53 +0100
* gnu/services/mcron.scm (mcron-configuration)[shepherd-requirement]: New field.
(list-of-symbols?): New predicate.
(mcron-shepherd-services): Add support for additional shepherd requirements.
* doc/guix.texi (Scheduled Job Execution): Update it.
---

Notable changes since v3:
* Implemented adjustable user, group and supplementary groups for mcron service.
  These are especially useful when configuring multiple instances. This also aligns
  with upstream recommendation to run multiple mcron instances with lesser
  privileged accounts.

Quoting mcron commit 0fe4d2cc9544d24ecc3e74a2d92433e01b9e25c6:
> I don't believe that anyone should be running system-wide cron processes these
> days (the attack surface is rather large), but should use separate per-user or
> per-service mcron daemon processes.

Tested with 'make check-system TESTS=mcron'.

 doc/guix.texi          |  4 ++++
 gnu/services/mcron.scm | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index a58ea8f9ec..56aa86118a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19379,6 +19379,10 @@ Scheduled Job Execution
 @item @code{mcron} (default: @code{mcron}) (type: file-like)
 The mcron package to use.
 
+@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbols)
+This is a list of symbols naming Shepherd services that this service
+will depend on.
+
 @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
diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm
index 2ef5980e09..99eb0edd60 100644
--- a/gnu/services/mcron.scm
+++ b/gnu/services/mcron.scm
@@ -32,6 +32,7 @@ (define-module (gnu services mcron)
   #:export (mcron-configuration
             mcron-configuration?
             mcron-configuration-mcron
+            mcron-configuration-shepherd-requirement
             mcron-configuration-jobs
             mcron-configuration-log?
             mcron-configuration-log-file
@@ -58,6 +59,9 @@ (define-module (gnu services mcron)
 (define list-of-gexps?
   (list-of gexp?))
 
+(define list-of-symbols?
+  (list-of symbol?))
+
 (define-maybe/no-serialization string)
 
 (define-configuration/no-serialization mcron-configuration
@@ -65,6 +69,11 @@ (define-configuration/no-serialization mcron-configuration
    (file-like mcron)
    "The mcron package to use.")
 
+  (shepherd-requirement
+   (list-of-symbols '())
+   "This is a list of symbols naming Shepherd services that this service
+will depend on.")
+
   (jobs
    (list-of-gexps '())
    "This is a list of gexps (@pxref{G-Expressions}), where each gexp
@@ -158,13 +167,13 @@ (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 shepherd-requirement jobs log? log-file log-format date-format)
     (if (eq? jobs '())
         '()                             ;nothing to do
         (let ((files (job-files mcron jobs)))
           (list (shepherd-service
                  (provision '(mcron))
-                 (requirement '(user-processes))
+                 (requirement `(user-processes ,@shepherd-requirement))
                  (modules `((srfi srfi-1)
                             (srfi srfi-26)
                             (ice-9 popen) ;for the 'schedule' action
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Sat, 01 Apr 2023 17:38:02 GMT) Full text and rfc822 format available.

Message #23 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v4 2/3] services: mcron: Add instance name support for mcron.
Date: Sat,  1 Apr 2023 18:35:54 +0100
Allow running more than one mcron instance.
Make log-file a mandatory field when instantiating
mcron-configuration records.

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

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





Information forwarded to guix-patches <at> gnu.org:
bug#62465; Package guix-patches. (Sat, 01 Apr 2023 17:45:02 GMT) Full text and rfc822 format available.

Message #26 received at 62465 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: 62465 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, maxim.cournoyer <at> gmail.com
Subject: [PATCH v4 3/3] services: mcron: Add user-name,
 user-group and supplementary-groups fields.
Date: Sat,  1 Apr 2023 18:35:55 +0100
Allows mcron to be launched with a different user. This is especially useful
when configuring multiple instances.

* gnu/services/mcron.scm
(mcron-configuration)[user, group, supplementary-groups]: New field.
(list-of-user-groups?): New predicate.
(mcron-shepherd-services): Use newly added fields.
* doc/guix.texi (Scheduled Job Execution): Update it.
---
 doc/guix.texi          |  9 +++++++++
 gnu/services/mcron.scm | 31 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index e2781cb439..1819e1386c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19387,6 +19387,15 @@ Scheduled Job Execution
 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{user} (type: maybe-user-account)
+Owner of the @command{mcron} process.
+
+@item @code{group} (type: maybe-user-group)
+Owner group of the @command{mcron} process.
+
+@item @code{supplementary-groups} (type: maybe-list-of-user-groups)
+List of supplementary groups of the @command{mcron} process.
+
 @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
diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm
index 164ef0e723..b4e28fc65d 100644
--- a/gnu/services/mcron.scm
+++ b/gnu/services/mcron.scm
@@ -23,6 +23,7 @@ (define-module (gnu services mcron)
   #:use-module (gnu services configuration)
   #:use-module (gnu services shepherd)
   #:use-module (gnu packages guile-xyz)
+  #:use-module (gnu system accounts)
   #:use-module (guix deprecation)
   #:use-module (guix records)
   #:use-module (guix gexp)
@@ -64,8 +65,14 @@ (define list-of-gexps?
 (define list-of-symbols?
   (list-of symbol?))
 
+(define list-of-user-groups?
+  (list-of user-group?))
+
 (define-maybe/no-serialization string)
 (define-maybe/no-serialization symbol)
+(define-maybe/no-serialization user-account)
+(define-maybe/no-serialization user-group)
+(define-maybe/no-serialization list-of-user-groups)
 
 (define-configuration/no-serialization mcron-configuration
   (mcron
@@ -82,6 +89,18 @@ (define-configuration/no-serialization mcron-configuration
    "Set the shepherd service name to @code{mcron-@var{instance}}.
 This is useful when you want to have more than one mcron instance.")
 
+  (user
+   maybe-user-account
+   "Owner of the @command{mcron} process.")
+
+  (group
+   maybe-user-group
+   "Owner group of the @command{mcron} process.")
+
+  (supplementary-groups
+   maybe-list-of-user-groups
+   "List of supplementary groups of the @command{mcron} process.")
+
   (jobs
    (list-of-gexps '())
    "This is a list of gexps (@pxref{G-Expressions}), where each gexp
@@ -178,6 +197,7 @@ (define (shepherd-schedule-action mcron files)
 (define (mcron-shepherd-services config)
   (match-record config <mcron-configuration>
     (mcron shepherd-requirement instance
+     user group supplementary-groups
      jobs log? log-file log-format date-format)
     (if (eq? jobs '())
         '()                             ;nothing to do
@@ -204,6 +224,17 @@ (define (mcron-shepherd-services config)
                                                 '()))
                                         '())
                                  #$@files)
+                           #$@(if (maybe-value-set? user)
+                                  `(#:user ,(user-account-name user))
+                                  '())
+                           #$@(if (maybe-value-set? group)
+                                  `(#:group ,(user-group-name group))
+                                  '())
+                           #$@(if (maybe-value-set? supplementary-groups)
+                                  `(#:supplementary-groups
+                                    ,#~'#$(map user-group-name
+                                               supplementary-groups))
+                                  '())
 
                            ;; Disable auto-compilation of the job files and
                            ;; set a sane value for 'PATH'.
-- 
2.39.1





This bug report was last modified 1 year and 232 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.