Sophisticated Azure VM

shutdown schedules

How to schedule Azure VM shutdowns without PowerShell?

Scheduling the start and shutdown of Azure VMs allows saving money on Azure costs.  A VM that has been shut down and deallocated does not incur any Azure charges (except for space it occupies in blob storage).  Shutting down VMs is usually beneficial for DEV/QA and other non-production environments, CI/build servers, or for production environments where access to VMs is required only during specific times.

In this case study, we’ll discuss how to shutdown cloud-based Microsoft Azure Virtual Machines on a schedule via CloudMonix.

The process takes just a few minutes and is easily replicable to any and all VMs in your Azure subscription.  It works for both Windows and Linux VMs and does not rely on somewhat complex and hard to maintain PowerShell scripts or Azure Automation runbooks.  Also, if any errors occur during either VM start or shutdown, you will get an immediate notification.

How to configure Stop and Shutdown actions to execute at a specific time

In order to configure the VM we need to define two actions: one to stop and one to start a VM at specific times:
To set up the Stop action:

  • Bring up an Edit dialog for a specific Azure VM from the CloudMonix dashboard and add a new action on the Actions tab;
  • specify the Name and Severity of the action;
  • ensure that Action execution is based on a Schedule rather than an Expression;
  • define a Start time of the action by creating a new Schedule entry of type Action Execution
CloudMonix - proactive reboots
  • Execution target should remain as “Self”;
  • Execution Command should be “AzureVmInstanceShutdownDeallocate”.  This will deallocate the VM and stop charges from Azure;
  • click on Save and Done.
CloudMonix - proactive reboots
To set up the Start action:

  • repeat the above steps to create a similar Start action;
  • use “AzureVmInstanceStart” command and a different time schedule instead.
Keep in mind that CloudMonix will also send out alerts in case of either success or failure of each action execution. Since the Schedule setup is quite flexible, it is possible to create any number of Start and Stop actions under a single resource to accommodate different schedules for weekdays and weekends, specific weeks of the month, etc.

Automating other VMs within the subscription

Once the initial actions have been configured, replicating these actions on other VMs to shut down and start on the same schedule is a fairly trivial task in CloudMonix:

  • save the configuration of the base VM as a template;
  • navigate to Resource Templates screen under Account Settings and open the previously saved template;
  • “push” the Start/Stop actions to any other VMs in your monitored setup.
CloudMonix - proactive reboots
Further reading on Azure VMs monitoring and automation with CloudMonix is available here.