From 270a126c6efd498798bb9342a12c0f671df51b4c Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 26 Nov 2018 22:38:18 +1100 Subject: [PATCH 2/3] system: Add --restart-services flag for reconfigure * gnu/services/shepherd.scm (always-restart, manually-restart, never-restart): Add restart-services? argument. * guix/scripts/system.scm (upgrade-shepherd-services): Add parameter to automatically restart services marked as needing manual restart. (switch-to-system, perform-action, process-action): Pass through restart-services? flag. (%options): Add --restart-services flag. (%default-options): Add #f as default value for --restart-services flag. --- gnu/services/shepherd.scm | 14 ++++++++------ guix/scripts/system.scm | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index f7e690fb0..638f6440c 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -146,19 +146,21 @@ DEFAULT is given, use it as the service's default value." (guix build utils) (guix build syscalls))) -(define (always-restart service) +(define (always-restart service restart-services?) "Unconditionally restart SERVICE and return #f." (let ((name (shepherd-service-canonical-name service))) (info (G_ "restarting service: ~a~%") name) (restart-service name) #f)) -(define (manually-restart service) - "Do not restart SERVICE, but return #t to indicate that the user should -restart it." - #t) +(define (manually-restart service restart-services?) + "Restart SERVICE and return #f if RESTART-SERVICES? is true, otherwise return #t to +indicate that the user should manually restart SERVICE." + (if restart-services? + (always-restart service #t) + #t)) -(define (never-restart service) +(define (never-restart service restart-services?) "Do not restart SERVICE and return #f." #f) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 26e35fe99..7c2699065 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -332,7 +332,7 @@ unload." (warning (G_ "failed to obtain list of shepherd services~%")) (return #f))))) -(define (upgrade-shepherd-services os) +(define (upgrade-shepherd-services os restart-services?) "Upgrade the Shepherd (PID 1) by unloading obsolete services and loading new services specified in OS and not currently running. @@ -381,7 +381,8 @@ bring the system down." (let* ((to-manually-restart (filter (lambda (service) ((shepherd-service-restart-strategy service) - service)) + service + restart-services?)) to-restart)) (to-manually-restart-names (map shepherd-service-canonical-name to-manually-restart))) @@ -391,7 +392,7 @@ bring the system down." (return #t))))))))) -(define* (switch-to-system os +(define* (switch-to-system os restart-services? #:optional (profile %system-profile)) "Make a new generation of PROFILE pointing to the directory of OS, switch to it atomically, and then run OS's activation script." @@ -419,7 +420,7 @@ it atomically, and then run OS's activation script." (primitive-load (derivation->output-path script)))) ;; Finally, try to update system services. - (upgrade-shepherd-services os)))) + (upgrade-shepherd-services os restart-services?)))) (define-syntax-rule (unless-file-not-found exp) (catch 'system-error @@ -827,7 +828,8 @@ and TARGET arguments." use-substitutes? bootloader-target target image-size file-system-type full-boot? (mappings '()) - (gc-root #f)) + (gc-root #f) + (restart-services? #f)) "Perform ACTION for OS. INSTALL-BOOTLOADER? specifies whether to install bootloader; BOOTLOADER-TAGET is the target for the bootloader; TARGET is the target root directory; IMAGE-SIZE is the size of the image to be built, for @@ -909,7 +911,7 @@ static checks." (case action ((reconfigure) (mbegin %store-monad - (switch-to-system os) + (switch-to-system os restart-services?) (mwhen install-bootloader? (install-bootloader bootloader-script #:bootcfg bootcfg @@ -1092,6 +1094,9 @@ Some ACTIONS support additional ARGS.\n")) (option '(#\r "root") #t #f (lambda (opt name arg result) (alist-cons 'gc-root arg result))) + (option '("restart-services") #f #f + (lambda (opt name arg result) + (alist-cons 'restart-services? #t result))) %standard-build-options)) (define %default-options @@ -1106,7 +1111,8 @@ Some ACTIONS support additional ARGS.\n")) (verbosity . 0) (file-system-type . "ext4") (image-size . guess) - (install-bootloader? . #t))) + (install-bootloader? . #t) + (restart-services? . #f))) ;;; @@ -1179,7 +1185,8 @@ resulting from command-line parsing." #:install-bootloader? bootloader? #:target target #:bootloader-target bootloader-target - #:gc-root (assoc-ref opts 'gc-root))))) + #:gc-root (assoc-ref opts 'gc-root) + #:restart-services? (assoc-ref opts 'restart-services?))))) #:system system)) (warn-about-disk-space))) -- 2.19.2