Share via

How to gracefully stop and restart applications running inside a VM during automated rightsizing operations

Sree Aravind M 20 Reputation points
2026-04-07T08:10:13.33+00:00

We are building an automated VM rightsizing solution that involves deallocating, resizing, and restarting Azure VMs based on utilization metrics. The challenge is that customer VMs may have various applications running inside them such as Docker containers, Java apps, databases, web servers, etc. When we deallocate the VM for resizing, these applications get stopped. After the VM restarts, there is no guarantee that applications will automatically come back up if the customer has not configured auto-start

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.


1 answer

Sort by: Most helpful
  1. Alex Burlachenko 19,770 Reputation points MVP Volunteer Moderator
    2026-04-08T09:53:52.1366667+00:00

    Sree Aravind M hi & thx for using Q&A platform )

    so back to urs question... this is not Azure problem, this is guest OS problem. Azure just stops the VM like pulling power. it has zero idea whats running inside, so if apps dont auto start they stay dead after resize. expected

    there is no universal “graceful stop all apps” button bc every VM is different. What people usually do either enforce app-level restart logic like

    systemd services for linux

    windows services / scheduled tasks

    docker with restart=always

    so after boot everything comes back automatically, or u handle it yourself before resize :) Run or Custom Script to execute inside VM

    stop apps gracefully (docker stop, systemctl stop, etc)

    then deallocate

    after start run another script to bring everything back

    basically u orchestrate it. If u wanna do it properly at scale use something like

    Azure Automation / Runbooks

    or your own agent inside VM

    so flow becomes

    call script inside VM graceful shutdown

    deallocate + resize

    start VM

    call script start apps

    but yeah key point

    Azure wont manage app lifecycle inside VM for u, ever

    rgds,

    Alex

    0 comments No comments

Your answer

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