mirror of https://github.com/rapenne-s/bento
bento: add auto reboot mode
This commit is contained in:
parent
4dfe31b6b1
commit
6de41994bf
|
@ -84,6 +84,7 @@ Here is the typical directory layout for using **bento** for the non-flakes syst
|
|||
`bento` is using the following environment variables as configuration:
|
||||
- `BENTO_DIR`: contains the path of a bento directory, so you can run `bento` commands from anywhere
|
||||
- `NAME`: contains machine names (flake config or directory in `hosts/`) to restrict commands `deploy` and `build` to this machine only
|
||||
- `VERBOSE`: if defined to anything, display `nixos-rebuild` output for local builds done with `bento build` or `bento deploy`
|
||||
|
||||
# Workflow
|
||||
|
||||
|
@ -109,6 +110,10 @@ Systems will be reported as "auto upgraded" in the `bento status` command if the
|
|||
|
||||
This adds at least 8 kB of inbound bandwidth for each input when checking for changes.
|
||||
|
||||
# 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).
|
||||
|
||||
# Examples
|
||||
|
||||
## Get started with bento
|
||||
|
@ -199,6 +204,8 @@ A parameter can be added to only update a given source with, i.e to update all n
|
|||
- DONE ~~upgrades could be triggered by the user by accessing a local socket, like opening a web page in a web browser to trigger it, if it returns output that'd be better~~
|
||||
- a way to tell a client (when using flakes) to try to update flakes every time even if no configuration changed, to keep them up to date
|
||||
- DONE ~~being able to use a single flakes with multiple hosts that **bento** will automatically assign to the nixosConfiguration names as hosts~~
|
||||
- DONE ~~handle automatic reboot if the kernel changed~~
|
||||
- automatic reboot should be scheduled if desired, this may require making bento a NixOS module to set a timer in it, if no timer then it would reboot immediately
|
||||
|
||||
## Minor
|
||||
|
||||
|
|
23
bento
23
bento
|
@ -334,6 +334,18 @@ then
|
|||
else
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_success.log.gz" | sftp ${dest}@${REMOTE_IP}:
|
||||
fi
|
||||
|
||||
# handle auto reboot if kernel changed
|
||||
if [ -f "REBOOT" ]
|
||||
then
|
||||
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
|
||||
fi
|
||||
else
|
||||
# check if we did a rollback
|
||||
if [ "\$SUCCESS" -eq 255 ]
|
||||
|
@ -374,6 +386,13 @@ build_config()
|
|||
TMPLOG="$(mktemp /tmp/bento-build-log.XXXXXXXXXXXX)"
|
||||
rsync -rltgoDL "$SOURCES/" "$TMP/"
|
||||
|
||||
if [ -z "VERBOSE" ]
|
||||
then
|
||||
output="/dev/null"
|
||||
else
|
||||
output="/dev/stderr"
|
||||
fi
|
||||
|
||||
SECONDS=0
|
||||
cd "$TMP" || exit 5
|
||||
|
||||
|
@ -385,9 +404,9 @@ build_config()
|
|||
test -d .git || git init >/dev/null 2>/dev/null
|
||||
git add . >/dev/null
|
||||
|
||||
$SUDO nixos-rebuild "${COMMAND}" --flake ".#${NAME}" 2>"${TMPLOG}" >"${TMPLOG}"
|
||||
$SUDO nixos-rebuild "${COMMAND}" --flake ".#${NAME}" | tee "${output}" 2>"${TMPLOG}" >"${TMPLOG}"
|
||||
else
|
||||
$SUDO nixos-rebuild "${COMMAND}" --no-flake -I nixos-config="$TMP/configuration.nix" 2>"${TMPLOG}" >"${TMPLOG}"
|
||||
$SUDO nixos-rebuild "${COMMAND}" --no-flake -I nixos-config="$TMP/configuration.nix" | tee "${output}" 2>"${TMPLOG}" >"${TMPLOG}"
|
||||
fi
|
||||
if [ $? -eq 0 ]; then printf "success " ; else printf "failure " ; BAD_HOSTS="${NAME} ${BAD_HOSTS}" ; SUCCESS=$(( SUCCESS + 1 )) ; cat "${TMPLOG}" ; fi
|
||||
ELAPSED=$(elapsed_time $SECONDS)
|
||||
|
|
Loading…
Reference in New Issue