Commit 07724eab authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

proxy: Remove the kernel container directory upon termination.

* guix/jupyter/proxy.scm (remove-kernel-directory): New procedure.
(terminate-proxied-kernel, terminate-proxied-kernels): Call it.
* guix/jupyter/kernel.scm (spawn-kernel/container): Remove FIXME
comment.
parent 1ccc88b0
...@@ -166,7 +166,6 @@ monadic value, a <kernel> connected to that process." ...@@ -166,7 +166,6 @@ monadic value, a <kernel> connected to that process."
;; network namespace. TODO: Arrange to use Unix-domain sockets instead. ;; network namespace. TODO: Arrange to use Unix-domain sockets instead.
(delq 'net %namespaces)) (delq 'net %namespaces))
;; FIXME: Remove ROOT once the kernel has terminated.
(mlet* %store-monad ((root ((lift0 make-container-directory %store-monad))) (mlet* %store-monad ((root ((lift0 make-container-directory %store-monad)))
(home -> (string-append root "/home")) (home -> (string-append root "/home"))
(pid (eval/container* (spawn profile) (pid (eval/container* (spawn profile)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#:use-module (jupyter servers) #:use-module (jupyter servers)
#:use-module (json) #:use-module (json)
#:use-module (gcrypt base16) #:use-module (gcrypt base16)
#:use-module ((guix build utils) #:select (delete-file-recursively))
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-9 gnu)
#:use-module (ice-9 vlist) #:use-module (ice-9 vlist)
...@@ -103,6 +104,18 @@ found." ...@@ -103,6 +104,18 @@ found."
(let ((count (proxy-state-execution-count state))) (let ((count (proxy-state-execution-count state)))
(set-proxy-state-execution-count state (+ 1 count)))) (set-proxy-state-execution-count state (+ 1 count))))
(define (remove-kernel-directory kernel)
"Return the directory used to store KERNEL's root and home directories, if
any."
;; Proxied kernels running in a container have their 'directory' property
;; set in 'spawn-kernel/container'.
(match (assq-ref (kernel-properties kernel) 'directory)
(#f #t)
((? string? directory)
(format/log "deleting '~a' of kernel ~a~%"
directory (kernel-pid kernel))
(delete-file-recursively directory))))
(define (terminate-proxied-kernel kernel) (define (terminate-proxied-kernel kernel)
"Send KERNEL a \"shutdown_request\" and terminate its process." "Send KERNEL a \"shutdown_request\" and terminate its process."
(define shutdown (define shutdown
...@@ -118,7 +131,8 @@ found." ...@@ -118,7 +131,8 @@ found."
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(kill (kernel-pid kernel) SIGTERM)) (kill (kernel-pid kernel) SIGTERM))
(const #t))) (const #t))
(remove-kernel-directory kernel))
(define (terminate-proxied-kernels message state) (define (terminate-proxied-kernels message state)
"Terminate all the proxies listed in the CONTAINERS vhash, sending them "Terminate all the proxies listed in the CONTAINERS vhash, sending them
...@@ -132,7 +146,8 @@ MESSAGE. Return the new state." ...@@ -132,7 +146,8 @@ MESSAGE. Return the new state."
#:kernel-socket kernel-control) #:kernel-socket kernel-control)
(unmonitor-client proxy) (unmonitor-client proxy)
(close-kernel proxy) (close-kernel proxy)
(false-if-exception (kill (kernel-pid proxy) SIGTERM)))) (false-if-exception (kill (kernel-pid proxy) SIGTERM))
(remove-kernel-directory proxy)))
(proxy-state-proxied state)) (proxy-state-proxied state))
(set-proxy-state-proxied state vlist-null)) (set-proxy-state-proxied state vlist-null))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment