From 98361e3555cd11f77c7ebe34dfa1ad1b7c7713ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20Rapenne?= Date: Sat, 24 Jun 2023 11:31:49 +0200 Subject: [PATCH] add a reboot timer --- doc/reference.md | 4 +++- utils/bento.nix | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/reference.md b/doc/reference.md index 5f1c7d9..e461bcc 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -55,7 +55,9 @@ This adds at least 8 kB of inbound bandwidth for each input when checking for ch # Auto reboot -You can create a file named `REBOOT` in a host directory. When that host will rebuild the system, it will look at the new kernel, kernel modules and initrd, if they changed, a reboot will occur immediately after reporting a successful upgrade. A kexec is used for UEFI systems for a faster reboot (this avoids BIOS and bootloader steps). +You can create a file named `REBOOT` in a host directory. When that host will rebuild the system, it will look at the new kernel, kernel modules and initrd, if they changed, a reboot will occur immediately after reporting a successful upgrade. A kexec is used for UEFI systems for a faster reboot (this avoids BIOS and bootloader steps). + +Independently of the `REBOOT` file, in the provided `utils/bento.nix`, there is a systemd service that can be enabled to automatically reboot at a given systemd calendar if the kernel/mdoules/initrd changed. This is more convenient for servers. # Status report of the fleet diff --git a/utils/bento.nix b/utils/bento.nix index 2e3bcc6..b4d3a73 100644 --- a/utils/bento.nix +++ b/utils/bento.nix @@ -17,6 +17,24 @@ in { restartIfChanged = false; }; + systemd.services.bento-reboot = { + # this is disabled by default + # to avoid wrong expectations from users + enable = false; + startAt = "04:00"; + path = with pkgs; [coreutils systemd]; + serviceConfig.Type = "oneshot"; + script = '' + booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})" + built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" + if [ ! "$booted" = "$built" ] + then + systemctl kexec || systemctl reboot + fi + ''; + }; + + systemd.sockets.listen-update = { enable = true; wantedBy = ["sockets.target"];