diff mbox series

[bug#54986,v2,2/3,WIP] services: shepherd: Add support for socket activation endpoints.

Message ID 454555484d434cefead47968e938ea071fe6121a.camel@gmail.com
State New
Headers show
Series [bug#54986] gnu: mpd: Add support for socket activation. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Liliana Marie Prikler April 23, 2022, 2:25 p.m. UTC
* gnu/services/shepherd.scm (<shepherd-endpoint>): New record type.
(shepherd-endpoint->sexp): New variable.
* doc/guix.texi (Shepherd Services): Document it.
---
 doc/guix.texi             | 29 +++++++++++++++++++
 gnu/services/shepherd.scm | 60 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)

Comments

Ludovic Courtès April 27, 2022, 10:05 p.m. UTC | #1
Hi,

Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:

> * gnu/services/shepherd.scm (<shepherd-endpoint>): New record type.
> (shepherd-endpoint->sexp): New variable.
> * doc/guix.texi (Shepherd Services): Document it.

[...]

> +++ b/gnu/services/shepherd.scm
> @@ -66,6 +66,16 @@ (define-module (gnu services shepherd)
>              shepherd-action-documentation
>              shepherd-action-procedure
>  
> +            shepherd-endpoint
> +            shepherd-endpoint-address
> +            shepherd-endpoint-name
> +            shepherd-endpoint-style
> +            shepherd-endpoint-backlog
> +            shepherd-endpoint-socket-owner
> +            shepherd-endpoint-socket-group
> +            shepherd-endpoint-socket-directory-permissions
> +            shepherd-endpoint->sexp
> +
>              %default-modules
>  
>              shepherd-service-file
> @@ -183,6 +193,56 @@ (define %default-modules
>      ((guix build utils) #:hide (delete))
>      (guix build syscalls)))
>  
> +(define-record-type* <shepherd-endpoint>

I don’t think this is necessary: Shepherd endpoints are created in a
#~(make-systemd-constructor …) gexp, it’s OK to use the Shepherd
endpoint API there.

Ludo’.
diff mbox series

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index 5399584cb0..38aeda1d2d 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -37675,6 +37675,35 @@  This, as you can see, is a fairly sophisticated way to say hello.
 info on actions.
 @end deftp
 
+@deftp {Data Type} shepherd-endpoint
+This is an endpoint that a systemd-style shepherd service listens on.
+
+@table @code
+@item address
+This is the socket address that shepherd binds and forwards to the service.
+
+@item name
+‾\_(ツ)_/‾
+
+@item style
+‾\_(ツ)_/‾
+
+@item backlog
+‾\_(ツ)_/‾
+
+@item socket-owner
+This is the user ID owning the socket.
+
+@item socket-group
+This is the group ID owning the socket.
+
+@item socket-directory-permissions
+These are the UNIX permissions to set for the directory the socket
+resides in.
+
+@end table
+@end deftp
+
 @defvr {Scheme Variable} shepherd-root-service-type
 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
 
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index 4fd4b2a497..3ef0023d7f 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -66,6 +66,16 @@  (define-module (gnu services shepherd)
             shepherd-action-documentation
             shepherd-action-procedure
 
+            shepherd-endpoint
+            shepherd-endpoint-address
+            shepherd-endpoint-name
+            shepherd-endpoint-style
+            shepherd-endpoint-backlog
+            shepherd-endpoint-socket-owner
+            shepherd-endpoint-socket-group
+            shepherd-endpoint-socket-directory-permissions
+            shepherd-endpoint->sexp
+
             %default-modules
 
             shepherd-service-file
@@ -183,6 +193,56 @@  (define %default-modules
     ((guix build utils) #:hide (delete))
     (guix build syscalls)))
 
+(define-record-type* <shepherd-endpoint>
+  shepherd-endpoint make-shepherd-endpoint
+  shepherd-endpoint?
+  (address                      shepherd-endpoint-address)      ; sockaddr
+  (name                         shepherd-endpoint-name          ; string | #f
+                                (default #f))
+  (style                        shepherd-endpoint-style         ; int | #f
+                                (default #f))
+  (backlog                      shepherd-endpoint-backlog       ; int | #f
+                                (default #f))
+  (socket-owner                 shepherd-endpoint-socket-owner  ; uid | #f
+                                (default #f))
+  (socket-group                 shepherd-endpoint-socket-group  ; gid | #f
+                                (default #f))
+  (socket-directory-permissions
+   shepherd-endpoint-socket-directory-permissions ; chmod pattern (int) | #f
+   (default #f)))
+
+(define (shepherd-endpoint->sexp endpoint)
+  (match endpoint
+    (($ <shepherd-endpoint> address
+                            name style backlog socket-owner socket-group
+                            socket-directory-permissions)
+     `(endpoint
+       ,(match (sockaddr:fam address)
+          ((? (cute = <> AF_INET) _)
+           `(make-socket-addr AF_INET
+                              ,(sockaddr:addr address)
+                              ,(sockaddr:port address)))
+          ((? (cute = <> AF_INET6) _)
+           `(make-socket-addr AF_INET6
+                              ,(sockaddr:addr address)
+                              ,(sockaddr:port address)
+                              ,(sockaddr:flowinfo address)
+                              ,(sockaddr:scopeid address)))
+          ((? (cute = <> AF_UNIX) _)
+           `(make-socket-addr AF_UNIX
+                              ,(sockaddr:path address))))
+       ,@(fold
+          (match-lambda*
+            (((key value) seed)
+             (if value (cons* key value seed) seed)))
+          '()
+          `((#:name ,name)
+            (#:style ,style)
+            (#:backlog ,backlog)
+            (#:socket-owner ,socket-owner)
+            (#:socket-group ,socket-group)
+            (#:socket-directory-permissions ,socket-directory-permissions)))))))
+
 (define-record-type* <shepherd-service>
   shepherd-service make-shepherd-service
   shepherd-service?