services: admin: Support rebooting after an unattended upgrade

* 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 <ludo@gnu.org>
This commit is contained in:
Richard Sent 2024-04-29 00:34:20 -04:00 committed by Ludovic Courtès
parent 2fcca2dafb
commit 85556e1dab
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 16 additions and 1 deletions

View File

@ -23088,6 +23088,10 @@ system to use for the upgrade. If no value is provided the
#~(@@ (guix system install) installation-os))) #~(@@ (guix system install) installation-os)))
@end lisp @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)}) @item @code{services-to-restart} (default: @code{'(mcron)})
This field specifies the Shepherd services to restart when the upgrade This field specifies the Shepherd services to restart when the upgrade
completes. completes.

View File

@ -420,6 +420,8 @@ which lets you search for packages that provide a given file.")
(default "30 01 * * 0")) (default "30 01 * * 0"))
(channels unattended-upgrade-configuration-channels (channels unattended-upgrade-configuration-channels
(default #~%default-channels)) (default #~%default-channels))
(reboot? unattended-upgrade-configuration-reboot?
(default #f))
(services-to-restart unattended-upgrade-configuration-services-to-restart (services-to-restart unattended-upgrade-configuration-services-to-restart
(default '(mcron))) (default '(mcron)))
(system-expiration unattended-upgrade-system-expiration (system-expiration unattended-upgrade-system-expiration
@ -443,6 +445,9 @@ which lets you search for packages that provide a given file.")
(define services (define services
(unattended-upgrade-configuration-services-to-restart config)) (unattended-upgrade-configuration-services-to-restart config))
(define reboot?
(unattended-upgrade-configuration-reboot? config))
(define expiration (define expiration
(unattended-upgrade-system-expiration config)) (unattended-upgrade-system-expiration config))
@ -512,7 +517,13 @@ which lets you search for packages that provide a given file.")
;; XXX: If 'mcron' has been restarted, perhaps this isn't ;; XXX: If 'mcron' has been restarted, perhaps this isn't
;; reached. ;; 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 (define upgrade
(program-file "unattended-upgrade" code)) (program-file "unattended-upgrade" code))