Disallow auto-reboot when users are active
This commit is contained in:
parent
5585164f1f
commit
b1cd6018ba
|
@ -119,6 +119,7 @@ in
|
|||
gitPull = true;
|
||||
gitDeploymentKeyFile = "/secrets/ssh_id_gitea_nixos_configuration";
|
||||
gitUser = "fruchti";
|
||||
rebootIgnoreUsersActive = [ "waldi" ];
|
||||
};
|
||||
|
||||
# systemd.services.nixos-upgrade.onFailure = lib.mkIf config.system.autoUpgrade.enable [ "status-email@%n.service" ];
|
||||
|
|
|
@ -36,6 +36,13 @@ in
|
|||
User used for the `git pull` operation (if `gitPull` is enabled).
|
||||
'';
|
||||
};
|
||||
rebootIgnoreUsersActive = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
description = mdDoc ''
|
||||
If reboots are allowed, active users will prohibit a reboot. Users listed here are ignored from that check.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
@ -156,6 +163,14 @@ in
|
|||
EOF
|
||||
)"
|
||||
activate_configuration="no"
|
||||
|
||||
# Check if any user sessions are open
|
||||
active_users=$(users | tr ' ' '\n' | sort | uniq | grep -vE '^(${concatStringsSep "|" cfg.rebootIgnoreUsersActive})$')
|
||||
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")"
|
||||
fi
|
||||
|
||||
if [ "$reboot_allowed" = "yes" ] && [ $exit_code -eq 0 ] ; then
|
||||
email_body="$(printf "%s\n%s" "$email_body" "The system will reboot now.")"
|
||||
do_reboot="yes"
|
||||
|
|
Loading…
Reference in a new issue