From: "Ludovic Courtès" <ludo@gnu.org>
To: 74860@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
"Ludovic Courtès" <ludo@gnu.org>,
"Maxim Cournoyer" <maxim.cournoyer@gmail.com>
Subject: [bug#74860] [PATCH 04/10] services: unattended-upgrade: Rewrite as a Shepherd timer.
Date: Fri, 13 Dec 2024 23:58:24 +0100 [thread overview]
Message-ID: <1ef30ffe4f1c8151279d93bd2331b4a21364b765.1734129908.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1734129908.git.ludo@gnu.org>
This is a semi-incompatible change: gexps previously provided in the
‘schedule’ field will no longer work.
* gnu/services/admin.scm (unattended-upgrade-mcron-jobs): Rename to…
(unattended-upgrade-shepherd-services): … this. Return a list of one
Shepherd service. Remove custom logging and time limitation facilities
from ‘code’.
(unattended-upgrade-service-type): Extend ‘shepherd-root-service-type’
instead of ‘mcron-service-type’.
(<unattended-upgrade-configuration>)[services-to-restart]: Change
default.
* doc/guix.texi (Unattended Upgrades): Adjust ‘schedule’ and
‘services-to-restart’ documentation.
Change-Id: I1b239c5946e71cf9e2af9b24fe4b01366b57fb7a
---
doc/guix.texi | 13 ++++----
gnu/services/admin.scm | 69 +++++++++++++++++++++++-------------------
2 files changed, 45 insertions(+), 37 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index e7784404d6..658081a9ed 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -23360,9 +23360,9 @@ Unattended Upgrades
@table @asis
@item @code{schedule} (default: @code{"30 01 * * 0"})
-This is the schedule of upgrades, expressed as a gexp containing an
-mcron job schedule (@pxref{Guile Syntax, mcron job specifications,,
-mcron, GNU@tie{}mcron}).
+This is the schedule of upgrades, expressed as a string in traditional
+cron syntax or as a gexp evaluating to a Shepherd calendar event
+(@pxref{Timers,,, shepherd, The GNU Shepherd Manual}).
@item @code{channels} (default: @code{#~%default-channels})
This gexp specifies the channels to use for the upgrade
@@ -23411,7 +23411,7 @@ Unattended Upgrades
rebooting. This means that the value for @code{services-to-restart} is
ignored. The updated services will be started after the system reboots.
-@item @code{services-to-restart} (default: @code{'(mcron)})
+@item @code{services-to-restart} (default: @code{'(unattended-upgrade)})
This field specifies the Shepherd services to restart when the upgrade
completes.
@@ -23426,8 +23426,9 @@ Unattended Upgrades
@xref{Services}, for general information about services. Common
services to restart would include @code{ntpd} and @code{ssh-daemon}.
-By default, the @code{mcron} service is restarted. This ensures that
-the latest version of the unattended upgrade job will be used next time.
+By default, the @code{unattended-upgrade} service is restarted. This
+ensures that the latest version of the unattended upgrade job will be
+used next time.
@item @code{system-expiration} (default: @code{(* 3 30 24 3600)})
This is the expiration time in seconds for system generations. System
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index aa1f56e90a..5fb2fcb6e0 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -517,7 +517,7 @@ (define-record-type* <unattended-upgrade-configuration>
(reboot? unattended-upgrade-configuration-reboot?
(default #f))
(services-to-restart unattended-upgrade-configuration-services-to-restart
- (default '(mcron)))
+ (default '(unattended-upgrade)))
(system-expiration unattended-upgrade-system-expiration
(default (* 3 30 24 3600)))
(maximum-duration unattended-upgrade-maximum-duration
@@ -528,7 +528,7 @@ (define-record-type* <unattended-upgrade-configuration>
(define %unattended-upgrade-log-file
"/var/log/unattended-upgrade.log")
-(define (unattended-upgrade-mcron-jobs config)
+(define (unattended-upgrade-shepherd-services config)
(define channels
(scheme-file "channels.scm"
(unattended-upgrade-configuration-channels config)))
@@ -536,6 +536,9 @@ (define (unattended-upgrade-mcron-jobs config)
(define log
(unattended-upgrade-configuration-log-file config))
+ (define schedule
+ (unattended-upgrade-configuration-schedule config))
+
(define services
(unattended-upgrade-configuration-services-to-restart config))
@@ -562,35 +565,17 @@ (define (unattended-upgrade-mcron-jobs config)
#~(begin
(use-modules (guix build utils)
(gnu services herd)
- (srfi srfi-19)
(srfi srfi-34))
- (define log
- (open-file #$log "a0"))
-
- (define (timestamp)
- (date->string (time-utc->date (current-time time-utc))
- "[~4]"))
-
- (define (alarm-handler . _)
- (format #t "~a time is up, aborting upgrade~%"
- (timestamp))
- (exit 1))
+ (setvbuf (current-output-port) 'line)
+ (setvbuf (current-error-port) 'line)
;; 'guix time-machine' needs X.509 certificates to authenticate the
;; Git host.
(setenv "SSL_CERT_DIR"
#$(file-append nss-certs "/etc/ssl/certs"))
- ;; Make sure the upgrade doesn't take too long.
- (sigaction SIGALRM alarm-handler)
- (alarm #$(unattended-upgrade-maximum-duration config))
-
- ;; Redirect stdout/stderr to LOG to save the output of 'guix' below.
- (redirect-port log (current-output-port))
- (redirect-port log (current-error-port))
-
- (format #t "~a starting upgrade...~%" (timestamp))
+ (format #t "starting upgrade...~%")
(guard (c ((invoke-error? c)
(report-invoke-error c)))
(apply invoke #$(file-append guix "/bin/guix")
@@ -609,23 +594,45 @@ (define (unattended-upgrade-mcron-jobs config)
(unless #$reboot?
;; Rebooting effectively restarts services anyway and execution
;; would be halted here if mcron is restarted.
- (format #t "~a restarting services...~%" (timestamp))
+ (format #t "restarting services...~%")
(for-each restart-service '#$services))
- ;; XXX: If 'mcron' has been restarted, this is not reached.
- (format #t "~a upgrade complete~%" (timestamp))
+ ;; XXX: If this service has been restarted, this is not reached.
+ (format #t "upgrade complete~%")
;; Stopping the root shepherd service triggers a reboot.
(when #$reboot?
- (format #t "~a rebooting system~%" (timestamp))
+ (format #t "rebooting system~%")
(force-output) ;ensure the entire log is written.
(stop-service 'root))))))
(define upgrade
(program-file "unattended-upgrade" code))
- (list #~(job #$(unattended-upgrade-configuration-schedule config)
- #$upgrade)))
+ (list (shepherd-service
+ (provision '(unattended-upgrade))
+ (requirement '(user-processes networking))
+ (modules '((shepherd service timer)))
+ (start #~(make-timer-constructor
+ #$(if (string? schedule)
+ #~(cron-string->calendar-event #$schedule)
+ schedule)
+ (command '(#$upgrade))
+
+ #:log-file #$log
+
+ ;; Make sure the upgrade doesn't take too long.
+ #:max-duration
+ #$(unattended-upgrade-maximum-duration config)
+
+ ;; Wait for the previous attempt to terminate before trying
+ ;; again.
+ #:wait-for-termination? #t))
+ (stop #~(make-timer-destructor))
+ (actions (list (shepherd-action
+ (name 'trigger)
+ (documentation "Trigger unattended system upgrade.")
+ (procedure #~trigger-timer)))))))
(define (unattended-upgrade-log-rotations config)
(list (log-rotation
@@ -636,8 +643,8 @@ (define unattended-upgrade-service-type
(service-type
(name 'unattended-upgrade)
(extensions
- (list (service-extension mcron-service-type
- unattended-upgrade-mcron-jobs)
+ (list (service-extension shepherd-root-service-type
+ unattended-upgrade-shepherd-services)
(service-extension rottlog-service-type
unattended-upgrade-log-rotations)))
(description
--
2.46.0
next prev parent reply other threads:[~2024-12-13 23:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 22:55 [bug#74860] [PATCH 00/10] Using the Shepherd's log rotation service Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 01/10] gnu: shepherd@1.0: Add dependency on gzip and zstd Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 02/10] services: Add ‘log-rotation-service-type’ Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 03/10] services: log-cleanup: Rewrite as a Shepherd timer Ludovic Courtès
2024-12-13 22:58 ` Ludovic Courtès [this message]
2024-12-13 22:58 ` [bug#74860] [PATCH 05/10] services: Switch from mcron + Rottlog to Shepherd’s log rotation Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 06/10] services: rottlog: Deprecate Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 07/10] DRAFT news: Add entry for ‘rottlog-service-type’ deprecation Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 08/10] home: services: Add log rotation service Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 09/10] home: Define ‘%base-home-services’ Ludovic Courtès
2024-12-13 22:58 ` [bug#74860] [PATCH 10/10] home: Add log rotation to ‘%base-home-services’ Ludovic Courtès
2024-12-13 23:20 ` [bug#74860] [PATCH 00/10] Using the Shepherd's log rotation service Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ef30ffe4f1c8151279d93bd2331b4a21364b765.1734129908.git.ludo@gnu.org \
--to=ludo@gnu.org \
--cc=74860@debbugs.gnu.org \
--cc=maxim.cournoyer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.