guix system: Use 'shepherd-service-lookup-procedure' in 'service-upgrade'.
* guix/scripts/system.scm (service-upgrade)[essential?]: SERVICE is now a <live-service>. [lookup-target, lookup-live, running?, stopped, obsolete?]: New procedures. [to-load, to-unload]: Use them. TO-UNLOAD is now a list of <live-service>. (call-with-service-upgrade-info): Extract symbols from TO-UNLOAD. * tests/system.scm ("service-upgrade: one unchanged, one upgraded, one new"): Adjust accordingly.
This commit is contained in:
parent
a5d78eb64b
commit
f20a7b8696
|
@ -273,41 +273,45 @@ on service '~a':~%")
|
||||||
#t)))
|
#t)))
|
||||||
|
|
||||||
(define (service-upgrade live target)
|
(define (service-upgrade live target)
|
||||||
"Return two values: the names of the subset of LIVE (a list of
|
"Return two values: the subset of LIVE (a list of <live-service>) that needs
|
||||||
<live-service>) that needs to be unloaded, and the subset of TARGET (a list of
|
to be unloaded, and the subset of TARGET (a list of <shepherd-service>) that
|
||||||
<shepherd-service>) that needs to be loaded."
|
needs to be loaded."
|
||||||
(define (essential? service)
|
(define (essential? service)
|
||||||
(memq service '(root shepherd)))
|
(memq (first (live-service-provision service))
|
||||||
|
'(root shepherd)))
|
||||||
|
|
||||||
(define new-service-names
|
(define lookup-target
|
||||||
(map (compose first shepherd-service-provision)
|
(shepherd-service-lookup-procedure target
|
||||||
target))
|
shepherd-service-provision))
|
||||||
|
|
||||||
(define running
|
(define lookup-live
|
||||||
(map (compose first live-service-provision)
|
(shepherd-service-lookup-procedure live
|
||||||
(filter live-service-running live)))
|
live-service-provision))
|
||||||
|
|
||||||
(define stopped
|
(define (running? service)
|
||||||
(map (compose first live-service-provision)
|
(and=> (lookup-live (shepherd-service-canonical-name service))
|
||||||
(remove live-service-running live)))
|
live-service-running))
|
||||||
|
|
||||||
|
(define (stopped service)
|
||||||
|
(match (lookup-live (shepherd-service-canonical-name service))
|
||||||
|
(#f #f)
|
||||||
|
(service (and (not (live-service-running service))
|
||||||
|
service))))
|
||||||
|
|
||||||
|
(define (obsolete? service)
|
||||||
|
(match (lookup-target (first (live-service-provision service)))
|
||||||
|
(#f #t)
|
||||||
|
(_ #f)))
|
||||||
|
|
||||||
(define to-load
|
(define to-load
|
||||||
;; Only load services that are either new or currently stopped.
|
;; Only load services that are either new or currently stopped.
|
||||||
(remove (lambda (service)
|
(remove running? target))
|
||||||
(memq (first (shepherd-service-provision service))
|
|
||||||
running))
|
|
||||||
target))
|
|
||||||
|
|
||||||
(define to-unload
|
(define to-unload
|
||||||
;; Unload services that are (1) no longer required, or (2) are in TO-LOAD.
|
;; Unload services that are (1) no longer required, or (2) are in TO-LOAD.
|
||||||
(remove essential?
|
(remove essential?
|
||||||
(append (remove (lambda (service)
|
(append (filter obsolete? live)
|
||||||
(memq service new-service-names))
|
(filter-map stopped to-load))))
|
||||||
(append running stopped))
|
|
||||||
(filter (lambda (service)
|
|
||||||
(memq service stopped))
|
|
||||||
(map shepherd-service-canonical-name
|
|
||||||
to-load)))))
|
|
||||||
|
|
||||||
(values to-unload to-load))
|
(values to-unload to-load))
|
||||||
|
|
||||||
|
@ -319,7 +323,9 @@ unload."
|
||||||
((services ...)
|
((services ...)
|
||||||
(let-values (((to-unload to-load)
|
(let-values (((to-unload to-load)
|
||||||
(service-upgrade services new-services)))
|
(service-upgrade services new-services)))
|
||||||
(mproc to-load to-unload)))
|
(mproc to-load
|
||||||
|
(map (compose first live-service-provision)
|
||||||
|
to-unload))))
|
||||||
(#f
|
(#f
|
||||||
(with-monad %store-monad
|
(with-monad %store-monad
|
||||||
(warning (_ "failed to obtain list of shepherd services~%"))
|
(warning (_ "failed to obtain list of shepherd services~%"))
|
||||||
|
|
|
@ -129,7 +129,7 @@
|
||||||
list))
|
list))
|
||||||
|
|
||||||
(test-equal "service-upgrade: one unchanged, one upgraded, one new"
|
(test-equal "service-upgrade: one unchanged, one upgraded, one new"
|
||||||
'((bar) ;unload
|
'(((bar)) ;unload
|
||||||
((bar) (baz))) ;load
|
((bar) (baz))) ;load
|
||||||
(call-with-values
|
(call-with-values
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -146,6 +146,7 @@
|
||||||
(shepherd-service (provision '(baz))
|
(shepherd-service (provision '(baz))
|
||||||
(start #t)))))
|
(start #t)))))
|
||||||
(lambda (unload load)
|
(lambda (unload load)
|
||||||
(list unload (map shepherd-service-provision load)))))
|
(list (map live-service-provision unload)
|
||||||
|
(map shepherd-service-provision load)))))
|
||||||
|
|
||||||
(test-end)
|
(test-end)
|
||||||
|
|
Loading…
Reference in New Issue