From 85556e1dab5040e9f570fd2606fef563bf0bbb83 Mon Sep 17 00:00:00 2001 From: Richard Sent Date: Mon, 29 Apr 2024 00:34:20 -0400 Subject: [PATCH] services: admin: Support rebooting after an unattended upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/services/admin.scm (unattended-upgrade-configuration): Add reboot? field. When truthy, unattended upgrade will stop the shepherd root service, triggering a reboot. * doc/guix.texi (Unattended Upgrades): Document it. Change-Id: I0af659b3c318421b1a7baa94dde3dadacc1fa10d Signed-off-by: Ludovic Courtès --- doc/guix.texi | 4 ++++ gnu/services/admin.scm | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index bdaefe3802..bc4d306c2d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -23088,6 +23088,10 @@ system to use for the upgrade. If no value is provided the #~(@@ (guix system install) installation-os))) @end lisp +@item @code{reboot?} (default: @code{#f}) +This field specifies whether the system should reboot after completing +an unattended upgrade. + @item @code{services-to-restart} (default: @code{'(mcron)}) This field specifies the Shepherd services to restart when the upgrade completes. diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 0b325fddb1..4882883878 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -420,6 +420,8 @@ (define-record-type* (default "30 01 * * 0")) (channels unattended-upgrade-configuration-channels (default #~%default-channels)) + (reboot? unattended-upgrade-configuration-reboot? + (default #f)) (services-to-restart unattended-upgrade-configuration-services-to-restart (default '(mcron))) (system-expiration unattended-upgrade-system-expiration @@ -443,6 +445,9 @@ (define log (define services (unattended-upgrade-configuration-services-to-restart config)) + (define reboot? + (unattended-upgrade-configuration-reboot? config)) + (define expiration (unattended-upgrade-system-expiration config)) @@ -512,7 +517,13 @@ (define (alarm-handler . _) ;; XXX: If 'mcron' has been restarted, perhaps this isn't ;; reached. - (format #t "~a upgrade complete~%" (timestamp)))))) + (format #t "~a upgrade complete~%" (timestamp)) + + ;; Stopping the root shepherd service triggers a reboot. + (when #$reboot? + (format #t "~a rebooting system~%" (timestamp)) + (force-output) ;ensure the entire log is written. + (stop-service 'root)))))) (define upgrade (program-file "unattended-upgrade" code))