From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id UF6nIkm5fmfAoQAAe85BDQ:P1 (envelope-from ) for ; Wed, 08 Jan 2025 17:43:37 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id UF6nIkm5fmfAoQAAe85BDQ (envelope-from ) for ; Wed, 08 Jan 2025 18:43:37 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XEjwBPZ2; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=D9YqZgzw; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736358217; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=dmVHySpjvJXWXi9jrxBVmLaf9JxKKQwLsN5EnAypjdI=; b=JS10VPd4T8lbY77QiOMVx9wtn6qhPnDJsZN7IEsI6OZHn5dsxEOSv2GnrwigOlp/ugBzf6 JyOx1uBr2dPbKGB94xzm9izOrZTFpvcvSjN4d5c3eSnLzi5gq4Hbi9V260AXjspcjHDnut 6M6fUi6WC6hxv582AGWpTpcUei2790HDC7JPL3A/vM5t4y3hSKlXrO8FXyJinKN2Id8NeQ MYDUOoe3jSB9noEh6LhtJ+72e1CL0Sa9BJVjBqX0GIhJkWiorUKF5LVyYI/pPcTHNjlfaW tPhxkwzw7iCA+JK7QDnXoM9Qw/rvq3bWaA+uUxQthjMD+EbJs0VO79EGnPfcOA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XEjwBPZ2; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=D9YqZgzw; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736358217; a=rsa-sha256; cv=none; b=J2fIzuSwRAy80oQ2E2lmdsoTuoFIlQoGx0hd1sv0XLPhMymT1DlsbHMI9e7NcVMOQ3ixhI CtOYWiID7A/qC/BYKxedn7WtgsGJlrt0wnWX1d5Y2TQJ+QGYh0DUQ8Oll4pGVdsEjjOOol g0S6jySvAoQmLdJeRw31KAm8/1boHY6Zzk8zrtIKOAH119i7OdzEviJ1Hlis5e5eor83zd mN0JXbqg0vbAi/kjmNlczcevlJHa7zYlHbNaCthEPxdSaTe9rmXikpFBti+Cju3bOwzb4L 3WjH4qTXQHIIkGBAbm78uMGqANhyOiPQ22DIWgVC3l/+xPTKlDzztCa7NCEX0Q== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 517847A06E for ; Wed, 08 Jan 2025 18:43:37 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVa5G-0005Xe-VH; Wed, 08 Jan 2025 12:43:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVa5A-0005Up-JL for guix-patches@gnu.org; Wed, 08 Jan 2025 12:43:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVa5A-00039S-9U; Wed, 08 Jan 2025 12:43:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=dmVHySpjvJXWXi9jrxBVmLaf9JxKKQwLsN5EnAypjdI=; b=XEjwBPZ2dZyoIXNUCQAmzPuIti86FqxPYKWYe+n3EEPs95BCGdzkVPNmcYBwrSlZOhq3h3mKF5YKWNr0U9D7aeaqp6eqCAF3Od0wM17jxi7d0LLL1EoaBbEXlJjoGCBYCp/DLPNtlunkEL3tJ7W7BqhqDth3woiNom7FRvAJAjxmBNhZ1OjKn7AHYe0TGSCo3/cJcdqadjxn12Qw81soncvvelSfD0vpsq8XS3OpPe/+PxbT5SKUPftCpP2ALqPz2N/ZbQ6BHpcvZNL5ReJbGIRSPNrN5hsj8WApDQaYQ+cdpJjxSJTHiQw15sNvEvi/djvf4F6yG26YmSj5y/upag==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tVa5A-0007sT-2H; Wed, 08 Jan 2025 12:43:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH v2 05/12] services: unattended-upgrade: Rewrite as a Shepherd timer. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 08 Jan 2025 17:43:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74860@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 74860-submit@debbugs.gnu.org id=B74860.173635815830142 (code B ref 74860); Wed, 08 Jan 2025 17:43:04 +0000 Received: (at 74860) by debbugs.gnu.org; 8 Jan 2025 17:42:38 +0000 Received: from localhost ([127.0.0.1]:48794 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tVa4j-0007po-PV for submit@debbugs.gnu.org; Wed, 08 Jan 2025 12:42:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60022) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tVa4d-0007oH-C8 for 74860@debbugs.gnu.org; Wed, 08 Jan 2025 12:42:32 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVa4X-0002uL-UD; Wed, 08 Jan 2025 12:42:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=dmVHySpjvJXWXi9jrxBVmLaf9JxKKQwLsN5EnAypjdI=; b=D9YqZgzwVmdL5r0byZAv S+FweXBQbienrHL6W8t7pHwirxCLNLp0t652sOSYNVxd1rvlKs8kioPEy7jHEb1eg7y7Kg8tdrAX/ xZIREPjsnATL6ceAz01lnPm7WtgiDLbiTZ/YBx7DS28k05pew0et1y/6whhkCsS0HM/31o9TXmkSr G2n11pgzNPh/3Ikm7KRehe9sgQhp1E06hgzzWwJMvqxzvVi6RzwJwtp4I9nOuRt70KUUgTzv5ZGti 3JBYjfu942dEEMH9eLojaNYtEACDn1H+Wepf4/pDOm/QIInh0jXKGtEa1eejQPuCMXQY0KBoVAzqy 3frjOdSRyERVsQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 8 Jan 2025 18:41:49 +0100 Message-ID: <564285438f6fa9498d1ecdcc9a7b0d00453651cf.1736357737.git.ludo@gnu.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 517847A06E X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: 0.33 X-Spam-Score: 0.33 X-TUID: qYEb9fvZBN/l 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’. ()[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 e1d08c2f10..bfd9ab1ab4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -23471,9 +23471,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 @@ -23522,7 +23522,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. @@ -23537,8 +23537,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 7d202d737e..735ba3f7be 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -553,7 +553,7 @@ (define-record-type* (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 @@ -564,7 +564,7 @@ (define-record-type* (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))) @@ -572,6 +572,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)) @@ -598,35 +601,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") @@ -645,23 +630,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 @@ -672,8 +679,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.47.1