summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-09-12 23:06:12 +0200
committerLudovic Courtès <ludo@gnu.org>2019-09-12 23:07:43 +0200
commitd236cd16a7173278ca69578d3e7ce4d1ce55e04c (patch)
tree80a8004b1d383e087745fdc8ecf231d3d370e0a5
parent3d8424a5ad96452ae2bfd98d970f6047cc17b5fa (diff)
linux-container: "run-container" scripts shows the container's PID.
* gnu/build/linux-container.scm (call-with-container): Add #:process-spawned-hook and honor it. * gnu/system/linux-container.scm (container-script)[script]: Define 'explain' and pass it as #:process-spawned-hook'.
-rw-r--r--gnu/build/linux-container.scm7
-rw-r--r--gnu/system/linux-container.scm19
2 files changed, 22 insertions, 4 deletions
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm
index 6ccb9248614..87695c98fdd 100644
--- a/gnu/build/linux-container.scm
+++ b/gnu/build/linux-container.scm
@@ -299,8 +299,10 @@ delete it when leaving the dynamic extent of this call."
299 (false-if-exception (delete-file-recursively tmp-dir)))))) 299 (false-if-exception (delete-file-recursively tmp-dir))))))
300 300
301(define* (call-with-container mounts thunk #:key (namespaces %namespaces) 301(define* (call-with-container mounts thunk #:key (namespaces %namespaces)
302 (host-uids 1) (guest-uid 0) (guest-gid 0)) 302 (host-uids 1) (guest-uid 0) (guest-gid 0)
303 "Run THUNK in a new container process and return its exit status. 303 (process-spawned-hook (const #t)))
304 "Run THUNK in a new container process and return its exit status; call
305PROCESS-SPAWNED-HOOK with the PID of the new process that has been spawned.
304MOUNTS is a list of <file-system> objects that specify file systems to mount 306MOUNTS is a list of <file-system> objects that specify file systems to mount
305inside the container. NAMESPACES is a list of symbols corresponding to 307inside the container. NAMESPACES is a list of symbols corresponding to
306the identifiers for Linux namespaces: mnt, ipc, uts, pid, user, and net. By 308the identifiers for Linux namespaces: mnt, ipc, uts, pid, user, and net. By
@@ -329,6 +331,7 @@ load path must be adjusted as needed."
329 (false-if-exception 331 (false-if-exception
330 (kill pid SIGKILL)))) 332 (kill pid SIGKILL))))
331 333
334 (process-spawned-hook pid)
332 (match (waitpid pid) 335 (match (waitpid pid)
333 ((_ . status) status)))))) 336 ((_ . status) status))))))
334 337
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index cca626be06e..c6124cd223b 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -171,11 +171,15 @@ that will be shared with the host system."
171 (define script 171 (define script
172 (with-imported-modules (source-module-closure 172 (with-imported-modules (source-module-closure
173 '((guix build utils) 173 '((guix build utils)
174 (gnu build linux-container))) 174 (gnu build linux-container)
175 (guix i18n)
176 (guix diagnostics)))
175 #~(begin 177 #~(begin
176 (use-modules (gnu build linux-container) 178 (use-modules (gnu build linux-container)
177 (gnu system file-systems) ;spec->file-system 179 (gnu system file-systems) ;spec->file-system
178 (guix build utils) 180 (guix build utils)
181 (guix i18n)
182 (guix diagnostics)
179 (srfi srfi-1)) 183 (srfi srfi-1))
180 184
181 (define file-systems 185 (define file-systems
@@ -187,6 +191,16 @@ that will be shared with the host system."
187 fs))) 191 fs)))
188 '#$specs)) 192 '#$specs))
189 193
194 (define (explain pid)
195 ;; XXX: We can't quite call 'bindtextdomain' so there's actually
196 ;; no i18n.
197 (info (G_ "system container is running as PID ~a~%") pid)
198 ;; XXX: Should we recommend 'guix container exec'? It's more
199 ;; verbose and doesn't bring much.
200 (info (G_ "Run 'sudo nsenter -a -t ~a' to get a shell into it.~%")
201 pid)
202 (newline (guix-warning-port)))
203
190 (call-with-container file-systems 204 (call-with-container file-systems
191 (lambda () 205 (lambda ()
192 (setenv "HOME" "/root") 206 (setenv "HOME" "/root")
@@ -201,7 +215,8 @@ that will be shared with the host system."
201 #:host-uids 65536 215 #:host-uids 65536
202 #:namespaces (if #$shared-network? 216 #:namespaces (if #$shared-network?
203 (delq 'net %namespaces) 217 (delq 'net %namespaces)
204 %namespaces))))) 218 %namespaces)
219 #:process-spawned-hook explain))))
205 220
206 (gexp->script "run-container" script))) 221 (gexp->script "run-container" script)))
207 222