sane-reboot: do a force reboot if the original command fails (experimental)

This commit is contained in:
2025-03-17 06:27:54 +00:00
parent 7ee91765fc
commit 470664d1c4
2 changed files with 7 additions and 2 deletions

View File

@@ -135,6 +135,10 @@ in
"sane-scripts.reboot".sandbox = {
method = "bunpen";
whitelistSystemctl = true;
capabilities = [
"sys_admin"
];
tryKeepUsers = true; #< allow `sudo sane-reboot`, for the case where the service manager is unreachable
};
"sane-scripts.reclaim-disk-space".sandbox = {

View File

@@ -9,8 +9,9 @@ if [ "$host" = "$target" ]
then
# N.B.: anything other than just `reboot` with no args requires `sudo` privileges (to write to /run/systemd/).
# `systemctl reboot -i` tells systemd to ignore inhibitors (i.e. other users logged in).
reboot "$@" || \
systemctl reboot -i "$@"
timeout 5 reboot "$@" || \
timeout 5 systemctl reboot -i "$@" || \
(sync && reboot --force --force "$@") #< XXX: requires root
else
echo "WRONG MACHINE. you're on $host."
exit 1