Auto-upgrade: Check for VMs, add more output
This commit is contained in:
parent
9aae1f5f83
commit
83b5a0df3d
1 changed files with 22 additions and 6 deletions
|
@ -52,6 +52,7 @@ in
|
|||
nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
|
||||
nix-store = "${pkgs.nix}/bin/nix-store";
|
||||
diff = "${pkgs.diffutils}/bin/diff";
|
||||
grep = "${pkgs.gnugrep}/bin/grep";
|
||||
git = "${pkgs.git}/bin/git";
|
||||
ssh = "${pkgs.openssh}/bin/ssh";
|
||||
sudo = "${pkgs.sudo}/bin/sudo";
|
||||
|
@ -164,11 +165,26 @@ in
|
|||
)"
|
||||
activate_configuration="no"
|
||||
|
||||
# Check if any user sessions are open
|
||||
active_users=$(users | tr ' ' '\n' | sort | uniq | grep -vE '^(${concatStringsSep "|" cfg.rebootIgnoreUsersActive})$' || true)
|
||||
if [ "$reboot_allowed" = "yes" ] && [ -n "$active_users" ] ; then
|
||||
reboot_allowed=no
|
||||
email_body="$(printf "%s\n%s\n%s" "$email_body" "The system cannot reboot since the following users are active:" "$active_users")"
|
||||
if [ "$reboot_allowed" = "yes" ] ; then
|
||||
echo "→ Checking if a reboot is allowed." | tee -a "$output_file"
|
||||
|
||||
# Check if any user sessions are open
|
||||
active_users=$(users | tr ' ' '\n' | sort | uniq | ${grep} -vE '^(${concatStringsSep "|" cfg.rebootIgnoreUsersActive})$' || true)
|
||||
if [ -n "$active_users" ] ; then
|
||||
reboot_allowed=no
|
||||
email_body="$(printf "%s\n%s\n%s" "$email_body" "The system cannot reboot since the following users are active:" "$active_users")"
|
||||
echo "$(echo $active_users | wc -l) active users blocking reboot." | tee -a "$output_file"
|
||||
fi
|
||||
|
||||
${optionalString config.virtualisation.libvirtd.enable ''
|
||||
# Check if virtual machines are running
|
||||
active_vms=$(${pkgs.libvirt}/bin/virsh list --state-running --no-autostart --id --name || true)
|
||||
if [ -n "$active_vms" ] ; then
|
||||
reboot_allowed=no
|
||||
email_body="$(printf "%s\n%s\n%s" "$email_body" "The system cannot reboot since the following virtual machines are active:" "$active_vms")"
|
||||
echo "$(echo $active_vms | wc -l) active VMs blocking reboot." | tee -a "$output_file"
|
||||
fi
|
||||
''}
|
||||
fi
|
||||
|
||||
if [ "$reboot_allowed" = "yes" ] && [ $exit_code -eq 0 ] ; then
|
||||
|
@ -193,7 +209,7 @@ in
|
|||
upgrade_output="$(cat "$output_file")"
|
||||
rm -f "$output_file"
|
||||
|
||||
possible_warnings="$(grep -e "^\(warning\|trace\|evaluation warning\):" <<<"$upgrade_output" || true)"
|
||||
possible_warnings="$(${grep} -e "^\(warning\|trace\|evaluation warning\):" <<<"$upgrade_output" || true)"
|
||||
if [ "$possible_warnings" != "" ] ; then
|
||||
send_email=yes
|
||||
email_subject_additions="$email_subject_additions with warnings"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue