me
/
guix
Archived
1
0
Fork 0

services: oci-container: Allow setting Shepherd actions in oci-container-configuration.

* gnu/services/docker.scm (oci-container-configuration)
[shepherd-actions]: New field.
(sanitize-shepherd-actions): sanitize it.
(oci-container-shepherd-service): use it.

* doc/guix.texi: Document it.

Change-Id: I0ca9826542be7cb8ca280a07a9bff1a262c2a8a7
Signed-off-by: Zheng Junjie <zhengjunjie@iscas.ac.cn>
master
Giacomo Leidi via Guix-patches via 2024-06-11 22:05:00 +02:00 committed by Zheng Junjie
parent cb57a3fd9f
commit 5ee2799cab
No known key found for this signature in database
GPG Key ID: 3B5AA993E1A2DFF0
2 changed files with 33 additions and 9 deletions

View File

@ -40898,6 +40898,10 @@ is @code{#f} the service has to be started manually with @command{herd start}.
Whether to have Shepherd restart the service when it stops, for instance when Whether to have Shepherd restart the service when it stops, for instance when
the underlying process dies. the underlying process dies.
@item @code{shepherd-actions} (default: @code{'()}) (type: list-of-symbols)
This is a list of @code{shepherd-action} records defining actions supported
by the service.
@item @code{network} (default: @code{""}) (type: string) @item @code{network} (default: @code{""}) (type: string)
Set a Docker network for the spawned container. Set a Docker network for the spawned container.

View File

@ -77,6 +77,7 @@
oci-container-configuration-log-file oci-container-configuration-log-file
oci-container-configuration-auto-start? oci-container-configuration-auto-start?
oci-container-configuration-respawn? oci-container-configuration-respawn?
oci-container-configuration-shepherd-actions
oci-container-configuration-network oci-container-configuration-network
oci-container-configuration-ports oci-container-configuration-ports
oci-container-configuration-volumes oci-container-configuration-volumes
@ -328,6 +329,17 @@ found!")
;; '(("/mnt/dir" . "/dir") "/run/current-system/profile:/java") ;; '(("/mnt/dir" . "/dir") "/run/current-system/profile:/java")
(oci-sanitize-mixed-list "volumes" value ":")) (oci-sanitize-mixed-list "volumes" value ":"))
(define (oci-sanitize-shepherd-actions value)
(map
(lambda (el)
(if (shepherd-action? el)
el
(raise
(formatted-message
(G_ "shepherd-actions may only be shepherd-action records
but ~a was found") el))))
value))
(define (oci-sanitize-extra-arguments value) (define (oci-sanitize-extra-arguments value)
(define (valid? member) (define (valid? member)
(or (string? member) (or (string? member)
@ -477,6 +489,11 @@ is @code{#f} the service has to be started manually with @command{herd start}.")
(boolean #f) (boolean #f)
"Whether to restart the service when it stops, for instance when the "Whether to restart the service when it stops, for instance when the
underlying process dies.") underlying process dies.")
(shepherd-actions
(list '())
"This is a list of @code{shepherd-action} records defining actions supported
by the service."
(sanitizer oci-sanitize-shepherd-actions))
(network (network
(maybe-string) (maybe-string)
"Set a Docker network for the spawned container.") "Set a Docker network for the spawned container.")
@ -680,6 +697,7 @@ operating-system, gexp or file-like records but ~a was found")
(oci-image-repository image)))))) (oci-image-repository image))))))
(let* ((docker (file-append docker-cli "/bin/docker")) (let* ((docker (file-append docker-cli "/bin/docker"))
(actions (oci-container-configuration-shepherd-actions config))
(auto-start? (auto-start?
(oci-container-configuration-auto-start? config)) (oci-container-configuration-auto-start? config))
(user (oci-container-configuration-user config)) (user (oci-container-configuration-user config))
@ -731,15 +749,17 @@ operating-system, gexp or file-like records but ~a was found")
(actions (actions
(if (oci-image? image) (if (oci-image? image)
'() '()
(list (append
(shepherd-action (list
(name 'pull) (shepherd-action
(documentation (name 'pull)
(format #f "Pull ~a's image (~a)." (documentation
name image)) (format #f "Pull ~a's image (~a)."
(procedure name image))
#~(lambda _ (procedure
(invoke #$docker "pull" #$image)))))))))) #~(lambda _
(invoke #$docker "pull" #$image)))))
actions))))))
(define %oci-container-accounts (define %oci-container-accounts
(list (user-account (list (user-account