Stop, deallocate and set auto-shutdown
In this task you'll stop and deallocate a VM.
You pay for a VM's processor and memory for every minute it's allocated, even if nobody is using it. Selecting Stop in the portal deallocates it: Azure releases the hardware and the compute charge stops.
Shutting the VM down from inside the operating system is different. The status shows Stopped, not Stopped (deallocated), and you keep paying. Auto-shutdown deallocates a VM at the same time every day, so you can't forget.
Example. Ironbridge Payments' test VMs only need to run during office hours, so each one has auto-shutdown at 7 pm. The team starts them again in the morning and pays for about a third of the hours.
Before you start
You need: Virtual Machine Contributor or Contributor. Time: 5 minutes.
Where to look
- Virtual machines
- vm-practice
- Overview
- Stop
Steps
- Open vm-practice. On Overview, select Stop and confirm.
- Wait until Status shows Stopped (deallocated).Only this status means the compute charge has stopped.
- Select Start to bring it back.A static public IP address, the default for new VMs, keeps the same address while the VM is stopped.
- Select Auto-shutdown in the left menu (under Operations).
- Turn it On, set a time such as 19:00 and your time zone, and add your email if you'd like a warning before it shuts down. Select Save.
Commands
# Stop AND deallocate (stops the compute charge)
az vm deallocate --resource-group rg-portal-practice --name vm-practice
# Note: 'az vm stop' powers off but keeps the VM allocated, so you still pay
# Start it again
az vm start --resource-group rg-portal-practice --name vm-practice
# Shut down automatically at 19:00 UTC every day
# (add --location <the VM's region> if it differs from the resource group's)
az vm auto-shutdown --resource-group rg-portal-practice --name vm-practice --time 1900
Watch out for
- Cost
- A deallocated VM has no compute charge, but its disks and a static public IP address are still billed. Delete the resource group when you no longer need the VM at all.
- Security
- Stopping a VM is a good habit for test machines: a VM that isn't running can't be attacked.
- Common mistakes
- Shutting down from inside Linux or Windows and thinking the meter has stopped. Forgetting that auto-shutdown doesn't start the VM again: you start it yourself.
Clean up
- Virtual machines
- vm-practice
- Auto-shutdown
Auto-shutdown can stay on: it's a good safety net while you practise. It's removed with the VM.
Words to know
- Deallocated
- The VM is stopped and its hardware is released, so compute charges stop. Disks are kept.
- Auto-shutdown
- A daily time at which Azure stops and deallocates the VM for you.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On