Package: guix-patches;
Reported by: Bruno Victal <mirai <at> makinata.eu>
Date: Sun, 26 Mar 2023 18:19:02 UTC
Severity: normal
Tags: patch
View this message in rfc822 format
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: [bug#62465] [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
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.