From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id OHBdJxu9XGdw6QAAe85BDQ:P1 (envelope-from ) for ; Fri, 13 Dec 2024 23:02:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id OHBdJxu9XGdw6QAAe85BDQ (envelope-from ) for ; Sat, 14 Dec 2024 00:02:51 +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=KQrVOzln; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="I/p9iU98"; 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=1734130971; 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=EpSyiz2tN3mFQnjdYouo4+8xssk+QQcrueQrjGy7xSs=; b=VCp7adzBxtP+UWfNu3FCa7IE1sshEzG+sFqNWzk0N+2bcxQysmmvuYlougbFHcHDi/m17l COXMc8KwfJ0PGXu9d0vKpkaYUYPr+XARFxhbSycjglrPfoPjSzfYtNH9HjZA4X5tfwl4hC PmFtV27UyNGgn8yHTpeyKkUIwTeEqeqeB67F1aN9zdQ7ZQ2TvMbRtVGpdgQP1UDkHb0SMk VvU2V6F/7DcxP81EL+NB5/+bY1YczHGY+BNg5cjtD8Ll903KIa2z0aGypdK6k64HKMP09m cy0RrrjBZXqjjAp7CjmNt1gKUxf4HCcP3PsuYZTM7fo8zZ7Kji8wtYcmR274mQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=KQrVOzln; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="I/p9iU98"; 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=1734130971; a=rsa-sha256; cv=none; b=sgEKJNFeQXe0UpdNZ1D6NhUAUk/5FSpvWQ4eh2E60x5lYlzrzNfG5JW3rGnV1ek1ZTZZHE eK6AXLjaCvwgcoKCycally0c/01JM564z680SHV/3UhV5sTgZTiqn4K6rJYIKrElc14PUK ecMoOVasoCplYy4f602P5RplPA80O8AbCFlD1tNZkcdtDyCVMNy2/yehS6dE+dZsHryX0E n0k9PoR1G4IyB+BHXF5mlguFza7HA3dT9CPi+FhYdmmgliVzIKajCLJ1DCg/BrKmNJbNkh f06JNibAsEmnDHQv255An+fEFSUGp1pAIKNwXK73YII5ktxwIDdkTAVlsDrmBw== 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 4264146CC7 for ; Sat, 14 Dec 2024 00:02:51 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMEff-0003xl-LV; Fri, 13 Dec 2024 18:02:08 -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 1tMEfb-0003wV-Vg for guix-patches@gnu.org; Fri, 13 Dec 2024 18:02:05 -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 1tMEfb-0002l9-HU; Fri, 13 Dec 2024 18:02: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=EpSyiz2tN3mFQnjdYouo4+8xssk+QQcrueQrjGy7xSs=; b=KQrVOzln3uElt8j3VTWmvkXyrQaerHsEqzOaV9gBfqZdDpO0Xk7fCOtyXgYK0wAn5568X+ATK7UkRkJyRKjudfRzNolbF1ANRr/akDZiQNWnau0ylq5Wd4gmXCzPOmHDD5eArrn4GQavW+V/QHIlPeC59CXE8keaKH809UUINNVZxsx2AHpdGhCNdxFTIxWtr5i8C0oUug/P1sH4UwZu9pDf/mDMSYJgsEuwGTFXbsem6uFDfZZXeIZfUbkKF+JSqu/7XmfKJ6IOLA2v+HWSWCZ52mrUmYVgNlrN49X64BP/WSC1RtPlpXC/GFgtQ0/NIu5Q+yslPpV0NVTL4RTq/w==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMEfb-0001YM-BZ; Fri, 13 Dec 2024 18:02:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74860] [PATCH 04/10] 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: Fri, 13 Dec 2024 23:02:03 +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.17341308835800 (code B ref 74860); Fri, 13 Dec 2024 23:02:03 +0000 Received: (at 74860) by debbugs.gnu.org; 13 Dec 2024 23:01:23 +0000 Received: from localhost ([127.0.0.1]:44558 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMEev-0001VM-Kr for submit@debbugs.gnu.org; Fri, 13 Dec 2024 18:01:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMEep-0001UV-HE for 74860@debbugs.gnu.org; Fri, 13 Dec 2024 18:01:16 -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 1tMEcd-0001n0-PM; Fri, 13 Dec 2024 17:58:59 -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=EpSyiz2tN3mFQnjdYouo4+8xssk+QQcrueQrjGy7xSs=; b=I/p9iU988aioNjko2uZe bRdxvE2GvM/CuSbZlqpTYTKxecNg/mKmK0fpgcFa1lKjDluIbiSJmqXpUfHVyvoegm+ZdY1gLj6hV RQjQ6s+7BOhZilG6dA2ZuiqtOa9Trf8tuOTOIn3sZdTAxI2x+osmA48CVtLddgHTXdZZi/+XCNc3i mG3Bxo+ZCHUV/Can7XbPL5rdhITRavj0Vu5cvINSeHHQcUWkV2jNL9oDdZ7v8t80X60YH0tIVEka3 RCx7PytBINP88rwDCROzeS8T5Z1rFuvzcfnaFyYNbmrAqZ7SKR22uq2s1Yx3eUhAVCxJOzg33F/EK xN9bY4ROLC1uCA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 Dec 2024 23:58:24 +0100 Message-ID: <1ef30ffe4f1c8151279d93bd2331b4a21364b765.1734129908.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 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-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 1.23 X-Spam-Score: 1.23 X-Migadu-Queue-Id: 4264146CC7 X-TUID: HQ+9T4iJ3Pmx 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 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* (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* (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