Skip to content

Commit

Permalink
Add offset for each VM instance, so they don't all reboot at the same…
Browse files Browse the repository at this point in the history
… time

5 minute increments are added to the scheduled reboot.
The hostname is parsed, and the suffix is used to determine which instance it is.
  • Loading branch information
s-fairchild committed Jun 10, 2024
1 parent 4dad153 commit 6d3cc99
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/deploy/assets/env-development.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/deploy/assets/gateway-production.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/deploy/assets/rp-production.json

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions pkg/deploy/generator/scripts/commonVMSS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ dnf_install_pkgs() {
retry cmd "$2" "${3:-}"
}

# configure_sshd
# We need to configure PasswordAuthentication to yes in order for the VMSS Access JIT to work
configure_sshd() {
log "starting"
Expand Down Expand Up @@ -422,6 +423,25 @@ enable_services() {
done
}

# get_reboot_offset
# Parses the last character from the short hostname, and assigns an offset to minutes
# Each increase in the hostname's suffix by 1 adds 5 minutes, starting with 0
# args:
# 1) minutes - nameref, integer; Empty variable used to hold the reboot offset minutes
get_reboot_offset() {
local -n minutes="$1"

host="${HOSTNAME: -1}"
local -i minutes_offset=0
# A loop is used to acccount for scaling up the VMSS after the initial 0-2 are created, rather than a case statement
for i in {0..100}; do
if [ "$host" -eq "$i" ]; then
minutes="$minutes_offset"
fi
((minutes_offset+=5))
done
}

# reboot_vm restores all selinux file contexts, then schedules a reboot for one hour later
# Reboots should scheduled after all VM extensions have had time to complete
# Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#tips
Expand All @@ -430,8 +450,10 @@ reboot_vm() {

configure_selinux "true"

hour="$(date -d "1 hour" +%H:%M)"
shutdown -r "$hour" "Post deployment reboot is happening now"
local -i offset
get_reboot_offset offset
hour="$(date -d "1 hour" +%H:%M + $offset minutes)"
shutdown -r "$hour" "Post deployment reboot is happening at $hour"
}

# configure_rpm_repos
Expand Down

0 comments on commit 6d3cc99

Please sign in to comment.