From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id CGovNiD0fmeZVwEAe85BDQ:P1 (envelope-from ) for ; Wed, 08 Jan 2025 21:54:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id CGovNiD0fmeZVwEAe85BDQ (envelope-from ) for ; Wed, 08 Jan 2025 22:54:41 +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=JsehYc8L; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=nwgz6807; 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=1736373280; 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=V3vksnI4v8JMXO/E5Av1ztBCJXiQInRqmXnHMO7k8JcjCgYYf6u3kA/Cd8QjRFoTIP/hj6 r21pYapNu9CygsvdrM/OF4xxGQCzM9uUEn92PD8oeFJnHssYMRTf/nNjhOIFUut1rNSPyn gaa0f4wucZB8EDfSWhPEnZutUamGJV3M4daIMS0OYRP+rIk+2O1dAzfe9pyXOfWmzV0Toe R9W2EBOasburHpiunIYPnsRN8tXnTt2eR+AyM/VIm6p2Mj1Hq7fNzlOd9uvwOVL+3Zb8Qu HOQIM/1VSCOl1APZ47aRjOC3AE2xujr4wXCR2MYFxpC7LfWRwcyZIAXmCCErUg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=JsehYc8L; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=nwgz6807; 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=1736373280; a=rsa-sha256; cv=none; b=TbuGloK26XmYh25f2PwI1LfzQFQnx68PrxlT0GGmOlLIx2Q4txuaXV0LKeZBnq5CsKIonB h18fpJtTUGJRKzWFHIryTOs8FEVDzK1gwbjO7p69zQta4CwifWZS8IGVB1ZqSHxYMxT0kA n3sYPpTpZ0oLvDYdIBpek63i6BB2c0YdIoNqqqdRfEg2LtybUrh1jUeizIN5zJG4y3xHpQ 0aCrP68Q+xdVtnFkgEC4KD9Dk/DsICW7IDGFRyfvPJ4RZLiuzuXhR3zXS6YFpylbo8oCMJ ifjKoq3QVOp42rAFxzfuUpb+f78nI/eyVEy+3fHCBe39y3uwGrGdYWqvx3Z6CQ== 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 9A34C1C316 for ; Wed, 08 Jan 2025 22:54:40 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVe0U-0000yT-SJ; Wed, 08 Jan 2025 16:54:30 -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 1tVe03-0008WI-AD for guix-patches@gnu.org; Wed, 08 Jan 2025 16:54: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 1tVe03-0004GK-14; Wed, 08 Jan 2025 16:54:03 -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=JsehYc8Le/OCl+YDbwvc3J2s88REqCl78cQ5qE2yLprhNkXPAQFL9NTkEX1I+RX4OQl96C34sidGVLGrQyBzz7id/ZgiOHIIRAvcEnOmly7tVZgDrJsOJ6kBnHGzGiQB+tWBvg+msTvTF+p+IdioM0qu7RXxdQsDpZBkuJPwC6Uto67p2J1vtI5rE+roLUx0Em5AY2PZDdmlP9aUy56kqVRpq9vozQe276f1cPSvOAqzImQWr4c/dwU6AGA2FzY2mU9sTSDF2t3uAoTV97ah8NV95gigc3RGhhjlOgSvXJuDh3UlOm+1pUCNrDEmL6VhXafwPEbAW9rWdFbHJxqK7Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tVe02-0005XZ-T9; Wed, 08 Jan 2025 16:54:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH v3 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 21:54:02 +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.173637319021163 (code B ref 74860); Wed, 08 Jan 2025 21:54:02 +0000 Received: (at 74860) by debbugs.gnu.org; 8 Jan 2025 21:53:10 +0000 Received: from localhost ([127.0.0.1]:49308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tVdzB-0005V5-Hj for submit@debbugs.gnu.org; Wed, 08 Jan 2025 16:53:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37980) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tVdz2-0005Sb-Rp for 74860@debbugs.gnu.org; Wed, 08 Jan 2025 16:53:01 -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 1tVdyx-00045x-H5; Wed, 08 Jan 2025 16:52:55 -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=nwgz6807aQ12xT9uD5Ml RppmTcukcRBaLx0DVadn88aOe/hd3RKa5n8O8oDdJsUirXzVb8I/Rkxuw2JYxJaG7FW+WpcBBAWkp snRpzX6EmEDmLsraYdUFh7Jkaqgu8lXlOPepVgG3MhR8/F2m5kZfW9iVHV0LvXArf6X5latUt+r4T QhJZiL1jMBoGbm0qd53rn8JBOhMiW8qSTp+9lRzZdX3d6Vy/21hdRPZpuC9WCjUtatktiCv+5AwRi e7q4EoIF8CaxzkqvGaJwlzZ4UkF12f1EEPgU9Zo81TwO9Xd/QGJVCDgGqBrXuhcVyOL5PNXbFaC9H YEdsELYT5kS1Ag==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 8 Jan 2025 22:51:53 +0100 Message-ID: <564285438f6fa9498d1ecdcc9a7b0d00453651cf.1736373022.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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -1.98 X-Spam-Score: -1.98 X-Migadu-Queue-Id: 9A34C1C316 X-TUID: bFns8Kg7V42b 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