summaryrefslogtreecommitdiff
path: root/gnu/system
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2025-09-23 15:34:55 +1000
committerLudovic Courtès <ludo@gnu.org>2025-11-13 21:55:42 +0100
commit0f96ceb58fd886c75f607cf6c540ae2ae361b70e (patch)
tree9e3d1622915f199ebeb689b38bdafbe9cc019e6b /gnu/system
parentca7de586054f7f3899b66fc8ba59d0bf6ab5b7db (diff)
gnu: Add --pid-file option to "guix system container" scripts.
* gnu/system/linux-container.scm (container-script): Accept pid-file command line option to write out the container's process ID. * doc/guix.texi (Invoking guix system): Document new option. Change-Id: I93e8a99b39c1dd831f116104bf92c723d96c9965 Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/system')
-rw-r--r--gnu/system/linux-container.scm21
1 files changed, 20 insertions, 1 deletions
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index 9bcdf24a7e0..87a2100fcc4 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -8,6 +8,7 @@
8;;; Copyright © 2023 Pierre Langlois <pierre.langlois@gmx.com> 8;;; Copyright © 2023 Pierre Langlois <pierre.langlois@gmx.com>
9;;; Copyright © 2024 Leo Nikkilä <hello@lnikki.la> 9;;; Copyright © 2024 Leo Nikkilä <hello@lnikki.la>
10;;; Copyright © 2024 Andreas Enge <andreas@enge.fr> 10;;; Copyright © 2024 Andreas Enge <andreas@enge.fr>
11;;; Copyright © 2025 Carlo Zancanaro <carlo@zancanaro.id.au>
11;;; 12;;;
12;;; This file is part of GNU Guix. 13;;; This file is part of GNU Guix.
13;;; 14;;;
@@ -247,6 +248,9 @@ Run the container with the given options."))
247 (display (G_ " 248 (display (G_ "
248 --expose=SPEC expose host file system directory as read-only 249 --expose=SPEC expose host file system directory as read-only
249 according to SPEC")) 250 according to SPEC"))
251 (display (G_ "
252 --pid-file=FILE write the process ID of the container's PID 1
253 process to FILE"))
250 (newline) 254 (newline)
251 (display (G_ " 255 (display (G_ "
252 -h, --help display this help and exit")) 256 -h, --help display this help and exit"))
@@ -267,6 +271,11 @@ Run the container with the given options."))
267 (lambda (opt name arg result) 271 (lambda (opt name arg result)
268 (alist-cons 'file-system-mapping 272 (alist-cons 'file-system-mapping
269 (specification->file-system-mapping arg #f) 273 (specification->file-system-mapping arg #f)
274 result)))
275 (option '("pid-file") #t #f
276 (lambda (opt name arg result)
277 (alist-cons 'pid-file
278 arg
270 result))))) 279 result)))))
271 280
272 (define (parse-options args options) 281 (define (parse-options args options)
@@ -290,6 +299,10 @@ Run the container with the given options."))
290 (newline (guix-warning-port))) 299 (newline (guix-warning-port)))
291 300
292 (let* ((opts (parse-options (cdr (command-line)) %options)) 301 (let* ((opts (parse-options (cdr (command-line)) %options))
302 (pid-files (filter-map (match-lambda
303 (('pid-file . filename) filename)
304 (_ #f))
305 opts))
293 (mappings (filter-map (match-lambda 306 (mappings (filter-map (match-lambda
294 (('file-system-mapping . mapping) mapping) 307 (('file-system-mapping . mapping) mapping)
295 (_ #f)) 308 (_ #f))
@@ -318,7 +331,13 @@ Run the container with the given options."))
318 (delq 'net %namespaces) 331 (delq 'net %namespaces)
319 %namespaces) 332 %namespaces)
320 #:writable-root? #t 333 #:writable-root? #t
321 #:process-spawned-hook explain))))) 334 #:process-spawned-hook (lambda (pid)
335 ;; Write out the PID to the requested files
336 (for-each (lambda (filename)
337 (call-with-output-file filename
338 (lambda (port) (write pid port))))
339 pid-files)
340 (explain pid)))))))
322 341
323 (gexp->script "run-container" script))) 342 (gexp->script "run-container" script)))
324 343