How can I make a VM in a scale set wait for systemd to gracefully shutdown?

Andrew Sayman 0 Reputation points
2024-09-25T21:04:52.53+00:00

I am interested in using VM scale sets for a workload with automatic scale in policies. Unfortunately it seems the scale down policy for shutting down the VMs that part of the scale set is overly aggressive. In my testing I've found that it waits at most 5 seconds before forcibly shutting off the VM. I have an application that needs more time to gracefully shutdown than that.

There are situations where my workload might need hours to shutdown the VM. I'd almost rather the VMs never shut themselves off without a graceful shutdown. In that scenario I can intervene if the data from the workload isn't offloaded.

Is there any way to achieve anything like this with VM scale sets?

Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
401 questions
{count} votes

1 answer

Sort by: Most helpful
  1. hossein jalilian 7,280 Reputation points
    2024-09-25T22:00:16.92+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    Unfortunately, Azure Virtual Machine Scale Sets do not currently provide a built-in way to allow for extended graceful shutdown periods during scale-in operations. The default behavior is indeed quite aggressive, with only a short window before forcibly terminating VMs.

    • You can implement a custom scale-in policy that selects VMs for removal based on specific criteria. This allows you to potentially flag VMs that are ready for shutdown
    • Configure a custom script extension on the VMs that runs before shutdown. This script could initiate your graceful shutdown process, though it would still be limited by the short termination window

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.