guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#62465] [PATCH v4 3/3] services: mcron: Add user-name, user-group an


From: Bruno Victal
Subject: [bug#62465] [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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]