Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unattended upgrades: Add hypervisor detection and use it for adjusting reboot time #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion debian-enable-unattended-upgrades.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# # Enable automatic reboots. Default is `false`.
# export UNATTENDED_REBOOT_ENABLE=true
#
# # Configure reboot time. Default is `04:00`.
# # Configure reboot time.
# # Default is `03:00` for hypervisor machines and `04:00` for guest machines.
# export UNATTENDED_REBOOT_TIME=22:00
#
# # Configure email notifications. Default is `no emails`.
Expand Down Expand Up @@ -53,7 +54,11 @@ COMMUNITY_REPOSITORIES_DISABLED="packages.grafana.com repo.mosquitto.org repos.i
# Set default values for optional configuration settings outlined above.
UNATTENDED_PACKAGE_TIME=${UNATTENDED_PACKAGE_TIME:-7,16:00}
UNATTENDED_REBOOT_ENABLE=${UNATTENDED_REBOOT_ENABLE:-false}
if is_hypervisor; then
UNATTENDED_REBOOT_TIME=${UNATTENDED_REBOOT_TIME:-03:00}
else
UNATTENDED_REBOOT_TIME=${UNATTENDED_REBOOT_TIME:-04:00}
fi


# ---------------
Expand Down Expand Up @@ -258,6 +263,14 @@ function activate_repository {
add_line "${line}"
}

function is_empty() {
# https://superuser.com/a/1284256
test -z $(find "$1" -mindepth 1 -printf X -quit)
}

function is_hypervisor() {
($(is_empty /proc/xen 2> /dev/null) && $(test ! -e /dev/kvm)) && return 1 || return 0
}


# ------------------
Expand Down