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 AM8yJpqMGmd6VAEAe85BDQ:P1 (envelope-from ) for ; Thu, 24 Oct 2024 18:06:18 +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 AM8yJpqMGmd6VAEAe85BDQ (envelope-from ) for ; Thu, 24 Oct 2024 20:06:18 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=HREYroNK; dkim=fail ("headers rsa verify failed") header.d=web.de header.s=s29768273 header.b=hm1zbEqh; 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=1729793178; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:list-id:list-help:list-unsubscribe:list-subscribe: list-post:dkim-signature; bh=fw7naxm5lCTQud8bUOz3EfhdKsVvkSzCkQWqfOj1ZoM=; b=W3MlslEzRtVLmb68bBRRAUqUidVMzFzjKvaGEi/ydAyKLQnsVELr+MvbyVFoMLeXyPz0f3 eGkHGyoOj5j0uR4FbMM2CxGWC+sZJJglwbYmf3jJ7PD9L0EMCkehPpdweel/4UQ/bQjxNY yo1ZAP6RlWtmYCYZhzFSYOKAbRq92arLFDuVCWajMQaZ6ymT3jjj0k4wtNPRoJkKaFOKeE X3B8y7agJk7E2foWGOI1jlWUOEbhLVHigB9tRVRN3O0gl5Dvo1KP8wGCTEubx3eSLt4/ZW V7YedaNjONZ1odm4IDBkAugBppylydkd7Ha61ijbAc5RI1064BrHAv5ZYKdJ6g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=HREYroNK; dkim=fail ("headers rsa verify failed") header.d=web.de header.s=s29768273 header.b=hm1zbEqh; 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=1729793178; a=rsa-sha256; cv=none; b=cyWwYgzXmads8s0XwIVJfWHruMi9mC7xmTtUWOlpXsCA3yqRnoOdbHUO3g1hCbHJ7walSa 4x/FwcB8NiYeI7kRUMSoHRrTNdV2ratL3iBwRXtzKdKmgNkHUHJarpmmux6vSH9v+b5Kob Z0uHz5k8IuaK40Fp2xnWnaUyVt4diYa5a0kAI52lsrMSJm9DT73/6ArsTzmNe9wCZIGSfP JDWYpOGqP7hDiXTyzQQK0Ha41F1XugllvD7Wrsfkg50cmfzjYpEp/N3Hjq9iC4q4PCT0zi ks9EZR5Fyi/2iEiQ4hc+2EcsJdxA3Sh63HakCZoHFxwiRand4J4UtOMNUUwk8g== 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 18ECC8C06F for ; Thu, 24 Oct 2024 20:06:17 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t42DG-0007rp-20; Thu, 24 Oct 2024 14:05:34 -0400 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 1t42DD-0007rG-T3 for guix-patches@gnu.org; Thu, 24 Oct 2024 14:05:31 -0400 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 1t42DD-0004Fn-KN for guix-patches@gnu.org; Thu, 24 Oct 2024 14:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:From:Date:To:Subject; bh=fw7naxm5lCTQud8bUOz3EfhdKsVvkSzCkQWqfOj1ZoM=; b=HREYroNK5Ycg8eDQLy7Sy+pXklmtxLZAvMaQPGM6Ml4uySg+8cq27+3U5EGg3Rptv8W4qR/AdpeQyKmQgVk6zUT9Mu+m0A9XQDoOyhoJ7kH3epHvf7pjXy1IlGAVf5js1WEDmjP5KS9fBqTVEajRRcc3oREBlUPrFG8DX9MjdSZ9bLzspaB/Wisply137XWkoFYy13fwxjTBtd2K3kgT0NeITeN+9+A2+DgCZJhxstuSH3XzqWlOGAAqCgNdD4B27B/EPiW5duRzxbZety9x7jHekGujn+ZoL2SVjSqZPVLwtDThZOCqPdxfA/PBEgX4cCXTaU2uuS/uWY4DPpFTkw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t42Di-0000JE-4x for guix-patches@gnu.org; Thu, 24 Oct 2024 14:06:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73992] [Shepherd PATCH] shepherd: Add support for rebooting using kexec Resent-From: Jakob Kirsch Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 24 Oct 2024 18:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73992 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73992@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1729793106705 (code B ref -1); Thu, 24 Oct 2024 18:06:01 +0000 Received: (at submit) by debbugs.gnu.org; 24 Oct 2024 18:05:06 +0000 Received: from localhost ([127.0.0.1]:36111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t42Ck-0000BD-Kg for submit@debbugs.gnu.org; Thu, 24 Oct 2024 14:05:06 -0400 Received: from lists.gnu.org ([209.51.188.17]:35202) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t42Cg-0000Ad-6A for submit@debbugs.gnu.org; Thu, 24 Oct 2024 14:05:01 -0400 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 1t42CA-0007jA-1M for guix-patches@gnu.org; Thu, 24 Oct 2024 14:04:26 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t42C4-0003zu-V8 for guix-patches@gnu.org; Thu, 24 Oct 2024 14:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1729793054; x=1730397854; i=jakob.kirsch@web.de; bh=fw7naxm5lCTQud8bUOz3EfhdKsVvkSzCkQWqfOj1ZoM=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=hm1zbEqhoPoiJNFo3m5bLFG9dCFHTadUL7/QLP6b+abiKqDwEWi1fAstP/xRURIj cU5mmU9KrYbxAdnYNed23+4rKPWkPpfnIuNNEVZgbOxlEjKIbscjn+zlPiO7KIjeq hLZh1FsR/PsvEed7cSUBk+2QBikVm081HU1guV8KCeNNizw7p61wzxZKBNqfquUdv ahWfV11Je8MIm1LDy1vHJnpRwPXghivUwn8WJJQp0VbPLNeZQ23NEYEr39OeeyAp1 KzrDTT+n933oyzY/0h/7pWX7ueB/QLHgt3jN1FeCyjKAuQmXVcT5Oldeii92vZqcP VqhD3k/gzP58O4WAWw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from kernelpanicroom ([134.19.29.168]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MHmm4-1t928e150g-000uY1 for ; Thu, 24 Oct 2024 20:04:14 +0200 Date: Thu, 24 Oct 2024 20:04:14 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5NGJD3urs9uYlo+0" Content-Disposition: inline X-Provags-ID: V03:K1:D8YrL0BgZpLiYkPd5PoBKFPczW3QjV98lWyAAJMS0L1UoSqXXcm Mgj1KRkn8RaiB1dUxEGwNf0C77BAmi8gLiEKJQ1PXmZNadnzwmCpawW5ysJivjqmTZcEhG+ lOsPpJIp4OR4HzHY/5bstgRp3WJL+ZeMYsYgdSsNOmUGQsF4Xh13tDK59W29Z3FkgGkcI7F 5lJtXO+Mo8oO1OeXWrikA== UI-OutboundReport: notjunk:1;M01:P0:5w71WscdXic=;RL4IOSJfzGRH2egHyWzQux4xiza yQjYrCTQ/RxaRjF8vdEwftPIcmDV0p12Ax89uepZoWQj33pio+lDvlEgM6xulwW3WGA6p/mVp mWXvqw06RYk3D+PytJdVjgnYc/dTf8jMMb++bL5FLn9B4eTr1bMm3zSRd1wC+fJVtOkf87y09 AddVZ1BVuGa23NR7qvTiWNxoN4hAq7mn/p7lIg50Zn0B8TrNNLUp7h7zy8Ofn30Y9p58lHq0G bWPZK+3c8Wd2svC7gsXPIlpNdWLnrWo8lNCZPHPyaZCqkzJgkXRfl3RpOT9oiG0wVXXtBJcGz xhXz9OC1iLFjsr5txBg5yR+SQg2XPtT6GMIrKnXZx3RN/5YtsGUWw9ZDi4F556i/tXnqDJQM+ ufL7lMcykazhatX8DHice0xupbDYFk7tRezF+bDzUeA/jqEXSuanD7ygyNhLHpUXqNu1vXWu0 HcZTKx6UOmjXm3hX0AhidMgQr6NinexH4dECXRzFaw8nVJj/I0ojN0mQeDx6wcLeTqvhus1RM pkGv5CgMMNuUtniC6QQU+UPM6KI1lqi3HxpFhggfcyI5WXsOGRbfuItrtfGwB+QdSWfhtvxi+ p8Wz68/U055nzWvi29IyLotjjJV2CoP31ZVkcRLwq7PMGqe/YG1gHuyx7+/0AC346jOAOEsQJ rKZpc6ypGtDyVInzeQoNcLHVPBIVU8pfokxnQtzW7zHyT1OlhQQI7MLtciAt6NfDY2jpoZ4/c hO1xcEeR9UcBSNLPoUI7WSG2+HbQ5u7viaEFB+DOXP27DQMOCVBTsfCYML9lrJuaGPD5EuLo5 7CZqkwX0s8Iuqz9wXgcdd4Yw== Received-SPF: pass client-ip=212.227.17.12; envelope-from=jakob.kirsch@web.de; helo=mout.web.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Reply-to: Jakob Kirsch X-ACL-Warn: , Jakob Kirsch via Guix-patches From: Jakob Kirsch via Guix-patches via 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: 2.01 X-Spam-Score: 2.01 X-Migadu-Queue-Id: 18ECC8C06F X-TUID: oPTtAjBdjm2L --5NGJD3urs9uYlo+0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This is my improved patch for using kexec with shepherd as I sent the last one to the wrong address (someone should update the description of the shepherd project to link to the correct patch submission list). --5NGJD3urs9uYlo+0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="v3-0001-shepherd-Add-support-for-rebooting-using-kexec.patch" Content-Transfer-Encoding: quoted-printable =46rom 762fbee53fb890a7cf5e26abcc2dcfad03b1bab4 Mon Sep 17 00:00:00 2001 From: Jakob Kirsch Date: Thu, 24 Oct 2024 19:45:31 +0200 Subject: [PATCH v3] shepherd: Add support for rebooting using kexec =2D-- AUTHORS | 1 + configure.ac | 4 ++++ doc/shepherd.texi | 9 +++++++++ modules/shepherd/scripts/reboot.scm | 12 ++++++++++-- modules/shepherd/service.scm | 9 +++++++++ modules/shepherd/system.scm.in | 10 ++++++++++ tests/status-sexp.sh | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 19132a7..6642bdc 100644 =2D-- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ when it was known as GNU dmd. Others have since contrib= uted: Alex Sassmannshausen David Thompson Andy Wingo + Jakob Kirsch diff --git a/configure.ac b/configure.ac index bcfef13..db1dc95 100644 =2D-- a/configure.ac +++ b/configure.ac @@ -124,6 +124,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include ]) AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include ]) AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include ]) + AC_COMPUTE_INT([RB_KEXEC], [RB_KEXEC], [#include ]) ;; gnu*) # On GNU/Hurd, the Mach-derived reboot.h uses different names, and @@ -131,6 +132,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT], [#include ]= ) AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT], [#include ]) RB_DISABLE_CAD=3D"#f" + RB_KEXEC=3D"#f" ;; *) # What is this? GNU/kFreeBSD? @@ -138,6 +140,7 @@ case "$host_os" in AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT_SYSTEM], [#include ]) AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT_SYSTEM], [#include ]) RB_DISABLE_CAD=3D"#f" + RB_KEXEC=3D"#f" ;; esac @@ -145,6 +148,7 @@ AC_SUBST([RB_DISABLE_CAD]) AC_SUBST([RB_AUTOBOOT]) AC_SUBST([RB_HALT_SYSTEM]) AC_SUBST([RB_POWER_OFF]) +AC_SUBST([RB_KEXEC]) AC_MSG_RESULT([done]) AC_MSG_CHECKING([ constants]) diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 0e627b3..921bf40 100644 =2D-- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -14,6 +14,7 @@ Copyright @copyright{} @value{NEW-YEARS} Ludovic Court= =E8s@* Copyright @copyright{} 2020 Brice Waegeneire@* Copyright @copyright{} 2020 Oleg Pykhalov@* Copyright @copyright{} 2020, 2023 Jan (janneke) Nieuwenhuizen@* +Copyright @copyright{} 2024 Jakob Kirsch@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -600,6 +601,14 @@ It is equivalent to running @command{herd stop shephe= rd}. The Send commands to the socket special file @var{file}. If this option is not specified, @file{@var{localstatedir}/run/shepherd/socket} is taken. +@item -k +@itemx --do-kexec +Reboot the system using kexec. The kernel that was previously loaded +using @command{kexec -l @var{file}} is executed instead of rebooting +into the BIOS in order to keep the down time to a minimum or to chainload +another kernel. This feature is only available on Linux-based systems and= will +throw an exception on GNU/Hurd. This is also equivalent to running @comma= nd{herd kexec shepherd}. + @end table @c @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ diff --git a/modules/shepherd/scripts/reboot.scm b/modules/shepherd/script= s/reboot.scm index 6be5414..4c2448e 100644 =2D-- a/modules/shepherd/scripts/reboot.scm +++ b/modules/shepherd/scripts/reboot.scm @@ -30,6 +30,8 @@ (define (main . args) (initialize-cli) + (define action 'stop) + (parameterize ((program-name "reboot")) (let ((socket-file %system-socket-file) (command-args '())) @@ -44,13 +46,19 @@ #:argument-name "FILE" #:description "send commands to FILE" #:action (lambda (file) - (set! socket-file file)))) + (set! socket-file file))) + (option + #:long-name "do-kexec" #:short-name #\k + #:takes-argument? #f + #:description "reboot using kexec" + #:action (lambda () (set! action 'kexec)) + )) (set! command-args (reverse command-args)) (with-system-error-handling (let ((sock (open-connection socket-file))) ;; Send the command without further ado. - (write-command (shepherd-command 'stop 'root) sock) + (write-command (shepherd-command action 'root) sock) ;; Receive output if we're not already dead. (match (read sock) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 5942b0a..6a5e112 100644 =2D-- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -2707,6 +2707,15 @@ Clients such as 'herd' can read it and format it in= a human-readable way." (lambda (key) (local-output (l10n "Shutting down...")) (power-off))))) + + (kexec + "Reboot the system and run kexec." + (lambda (running) + (catch 'quit + (cut stop root-service) + (lambda (key) + (local-output (l10n "Rebooting with kexec...")) + (reboot-kexec))))) ;; Evaluate arbitrary code. (load "Load the Scheme code from FILE into shepherd. This is potentially diff --git a/modules/shepherd/system.scm.in b/modules/shepherd/system.scm.= in index 4c83175..1168c15 100644 =2D-- a/modules/shepherd/system.scm.in +++ b/modules/shepherd/system.scm.in @@ -26,6 +26,7 @@ #:use-module (srfi srfi-26) #:export (disable-reboot-on-ctrl-alt-del reboot + reboot-kexec halt power-off max-file-descriptors @@ -51,6 +52,7 @@ (define RB_HALT_SYSTEM @RB_HALT_SYSTEM@) (define RB_POWER_OFF @RB_POWER_OFF@) (define RB_DISABLE_CAD @RB_DISABLE_CAD@) ; integer | #f +(define RB_KEXEC @RB_KEXEC@) ; integer | #f (define (syscall->procedure return-type name argument-types) "Return a procedure that wraps the C function NAME using the dynamic FF= I, @@ -95,6 +97,14 @@ ctrlaltdel(8) and see kernel/reboot.c in Linux." "Perform a hard reset of the system now. Return #f on failure." (%libc-reboot RB_AUTOBOOT)) +(define (reboot-kexec) + "Execute kernel loaded with 'kexec -l' now. Kexec is a feature of the +Linux kernel that allows you to instantly reboot into a new kernel while = skipping +the BIOS phase. Return #f on failure or throw an exception on non-Linux = systems." + (if RB_KEXEC + (%libc-reboot RB_KEXEC) + (throw 'system-error 'kexec "~A" (list (strerror ENOSYS)) (list ENOS= YS)))) + (define (halt) "Halt the system. Return #f on failure." (%libc-reboot RB_HALT_SYSTEM)) diff --git a/tests/status-sexp.sh b/tests/status-sexp.sh index 14b1e72..3fa0283 100644 =2D-- a/tests/status-sexp.sh +++ b/tests/status-sexp.sh @@ -91,7 +91,7 @@ root_service_sexp=3D" (transient? #f) (respawn-limit (5 . 7)) (respawn-delay 0.1) - (actions (help status halt power-off load eval unload reload daemon= ize restart)) + (actions (help status halt power-off kexec load eval unload reload = daemonize restart)) (exit-statuses ()) (recent-messages ()) (log-files (\"$PWD/$log\")) =2D- 2.46.0 --5NGJD3urs9uYlo+0--