From unknown Mon Aug 18 21:50:54 2025 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 From: Jakob Kirsch 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== X-Spam-Flag: NO 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-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --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-- From unknown Mon Aug 18 21:50:54 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Jakob Kirsch Subject: bug#73992: closed (Re: bug#73992: [Shepherd PATCH] shepherd: Add support for rebooting using kexec) Message-ID: References: <87r07sl6j1.fsf@gnu.org> X-Gnu-PR-Message: they-closed 73992 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 73992@debbugs.gnu.org Date: Sun, 03 Nov 2024 14:47:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1730645222-4913-1" This is a multi-part message in MIME format... ------------=_1730645222-4913-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73992: [Shepherd PATCH] shepherd: Add support for rebooting using kexec which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73992@debbugs.gnu.org. --=20 73992: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73992 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1730645222-4913-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73992-done) by debbugs.gnu.org; 3 Nov 2024 14:46:28 +0000 Received: from localhost ([127.0.0.1]:60807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t7bs1-0001GD-3A for submit@debbugs.gnu.org; Sun, 03 Nov 2024 09:46:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t7brv-0001G3-LA for 73992-done@debbugs.gnu.org; Sun, 03 Nov 2024 09:46:23 -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 1t7brp-0004RH-Sa; Sun, 03 Nov 2024 09:46:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=hbQitByjXNU1SPKoefdnEoS1F/BdooOOeTPPd9izjEs=; b=iExh7tjEouGHIhqsD3Dy jJ6Gp9LnSp03KfP3uXQXS7syTsY7EMx94/0LjTlAYicaPOjakgZxNwAI6MkJlqnUGKxT9Gk9N7v5M u5PApR8jMGBSpPUp6KZUbS34USUAD0Rx5LR7mbxtvrfrd8Lqh/vU4A5BECvTBJ6nRVARAEQSo0HGO ky1RvPqmCHcSNhFtpDj/kG2sxK43FayhCsM5TPmCSNw5KxS6XrhiIy7iwCiWzLceQXbRsWgry7/QF ZVvpMvgHCY94Yrs9NzktiisYuIycpQ+Wvnb8ceq6Uv30y6qlfihWLtR2u7z5vZSck2J/rMOZwGYKp SinaDy8ZbPuirQ==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Jakob Kirsch Subject: Re: bug#73992: [Shepherd PATCH] shepherd: Add support for rebooting using kexec In-Reply-To: (Jakob Kirsch's message of "Thu, 24 Oct 2024 20:04:14 +0200") References: Date: Sun, 03 Nov 2024 15:46:10 +0100 Message-ID: <87r07sl6j1.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73992-done Cc: 73992-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Jakob, Jakob Kirsch skribis: > From 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 > > --- > 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(-) I applied it to the =E2=80=98devel=E2=80=99 branch after making the cosmeti= c changes below (let me know if anything is amiss). I also added a commit log that follows the project=E2=80=99s conventions. Thank you! Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/doc/shepherd.texi b/doc/shepherd.texi index faef6f1..b164fe8 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -516,12 +516,15 @@ Send commands to the socket special file @var{file}. = If this option is not specified, @file{@var{localstatedir}/run/shepherd/socket} is taken. =20 @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 @comman= d{herd kexec shepherd}. +@itemx --kexec +Reboot the system using Linux's kexec (this is equivalent to running +@command{herd kexec root}). The kernel that was previously loaded using +the @command{kexec -l @var{file}} command is executed directly instead +of rebooting into the BIOS, keeping the downtime to a minimum. See the +@uref{https://linux.die.net/man/8/kexec, @command{kexec} command +documentation} for more information. + +This feature is only available on Linux-based systems. =20 @end table =20 diff --git a/modules/shepherd/scripts/reboot.scm b/modules/shepherd/scripts= /reboot.scm index 4c2448e..0f3fc30 100644 --- a/modules/shepherd/scripts/reboot.scm +++ b/modules/shepherd/scripts/reboot.scm @@ -1,5 +1,6 @@ ;; reboot.scm -- Reboot the system. ;; Copyright (C) 2013, 2014, 2015, 2016, 2018, 2023 Ludovic Court=C3=A8s <= ludo@gnu.org> +;; Copyright (C) 2024 Jakob Kirsch ;; ;; This file is part of the GNU Shepherd. ;; @@ -48,11 +49,11 @@ #:action (lambda (file) (set! socket-file file))) (option - #:long-name "do-kexec" #:short-name #\k + #:long-name "kexec" #:short-name #\k #:takes-argument? #f #:description "reboot using kexec" - #:action (lambda () (set! action 'kexec)) - )) + #:action (lambda () + (set! action 'kexec)))) =20 (set! command-args (reverse command-args)) (with-system-error-handling diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 6a5e112..08a9df2 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -2709,13 +2709,14 @@ Clients such as 'herd' can read it and format it in= a human-readable way." (power-off))))) =20 (kexec - "Reboot the system and run kexec." - (lambda (running) + "Reboot the system and run kexec." + (lambda (running) (catch 'quit - (cut stop root-service) + (cut stop-service 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 1168c15..46f1848 100644 --- a/modules/shepherd/system.scm.in +++ b/modules/shepherd/system.scm.in @@ -2,6 +2,7 @@ ;; Copyright (C) 2013-2014, 2016, 2018, 2020, 2022-2024 Ludovic Court=C3= =A8s ;; Copyright (C) 2018 Carlo Zancanaro ;; Copyright (C) 2020 Jan (janneke) Nieuwenhuizen +;; Copyright (C) 2024 Jakob Kirsch ;; ;; This file is part of the GNU Shepherd. ;; @@ -98,12 +99,13 @@ ctrlaltdel(8) and see kernel/reboot.c in Linux." (%libc-reboot RB_AUTOBOOT)) =20 (define (reboot-kexec) - "Execute kernel loaded with 'kexec -l' now. Kexec is a feature of the + "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 s= kipping the BIOS phase. Return #f on failure or throw an exception on non-Linux s= ystems." (if RB_KEXEC - (%libc-reboot RB_KEXEC) - (throw 'system-error 'kexec "~A" (list (strerror ENOSYS)) (list ENOSY= S)))) + (%libc-reboot RB_KEXEC) + (throw 'system-error 'kexec "~A" (list (strerror ENOSYS)) + (list ENOSYS)))) =20 (define (halt) "Halt the system. Return #f on failure." --=-=-=-- ------------=_1730645222-4913-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit 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 From: Jakob Kirsch To: guix-patches@gnu.org Subject: [Shepherd PATCH] shepherd: Add support for rebooting using kexec 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== X-Spam-Flag: NO 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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --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-- ------------=_1730645222-4913-1--