diff options
author | Ludovic Courtès <ludo@gnu.org> | 2016-08-30 22:40:24 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2016-08-31 15:44:20 +0200 |
commit | b8692e4696d0d2b36466827da1e0d25d69a298af (patch) | |
tree | c073388b0b4761f0fa719bc3ba66f3964de3dfd9 /guix | |
parent | 183605c8533ad321ff8bba209b64071a9e84714a (diff) | |
download | gnu-guix-b8692e4696d0d2b36466827da1e0d25d69a298af.tar gnu-guix-b8692e4696d0d2b36466827da1e0d25d69a298af.tar.gz |
guix system: Extract and test the service upgrade procedure.
* guix/scripts/system.scm (service-upgrade): New procedure, with code
from...
(call-with-service-upgrade-info): ... here. Use it.
* tests/system.scm (live-service, service-upgrade): New variables.
("service-upgrade: nothing to do", "service-upgrade: one unchanged, one
upgraded, one new"): New tests.
Diffstat (limited to 'guix')
-rw-r--r-- | guix/scripts/system.scm | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 55a8e475d4..a006b2d54e 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -272,40 +272,53 @@ on service '~a':~%") ((not error) ;not an error #t))) -(define (call-with-service-upgrade-info new-services mproc) - "Call MPROC, a monadic procedure in %STORE-MONAD, passing it the list of -names of services to load (upgrade), and the list of names of services to -unload." +(define (service-upgrade live target) + "Return two values: the names of the subset of LIVE (a list of +<live-service>) that needs to be unloaded, and the subset of TARGET (a list of +<shepherd-service>) that needs to be loaded." (define (essential? service) (memq service '(root shepherd))) (define new-service-names (map (compose first shepherd-service-provision) - new-services)) + target)) + + (define running + (map (compose first live-service-provision) + (filter live-service-running live))) + + (define stopped + (map (compose first live-service-provision) + (remove live-service-running live))) + + (define to-load + ;; Only load services that are either new or currently stopped. + (remove (lambda (service) + (memq (first (shepherd-service-provision service)) + running)) + target)) + + (define to-unload + ;; Unload services that are (1) no longer required, or (2) are in TO-LOAD. + (remove essential? + (append (remove (lambda (service) + (memq service new-service-names)) + (append running stopped)) + (filter (lambda (service) + (memq service stopped)) + (map shepherd-service-canonical-name + to-load))))) + + (values to-unload to-load)) +(define (call-with-service-upgrade-info new-services mproc) + "Call MPROC, a monadic procedure in %STORE-MONAD, passing it the list of +names of services to load (upgrade), and the list of names of services to +unload." (match (current-services) ((services ...) - (let* ((running (map (compose first live-service-provision) - (filter live-service-running services))) - (stopped (map (compose first live-service-provision) - (remove live-service-running services))) - (to-load - ;; Only load services that are either new or currently stopped. - (remove (lambda (service) - (memq (first (shepherd-service-provision service)) - running)) - new-services)) - (to-unload - ;; Unload services that are (1) no longer required, or (2) are - ;; in TO-LOAD. - (remove essential? - (append (remove (lambda (service) - (memq service new-service-names)) - (append running stopped)) - (filter (lambda (service) - (memq service stopped)) - (map shepherd-service-canonical-name - to-load)))))) + (let-values (((to-unload to-load) + (service-upgrade services new-services))) (mproc to-load to-unload))) (#f (with-monad %store-monad |