Skip to content

Start stop VM's

In this project, we’re going to automate the code for building Red Hat Management Tools to manage and build a Red Hat based environment. Since the environment isn’t going to be used for productive workloads, we’ve decided to use a built-in functionality from the Microsoft Azure Marketplace called start/stop VMs v2. This will help decrease cloud costs for non-development time slots in the project, such as evenings and weekends.

The Start/Stop VMs v2 feature starts or stops Azure Virtual Machines instances across multiple subscriptions.

We’ve decided to take a different approach to the automation code development for this project. While this isn’t the main requirement, we’ve agreed to exclude this part and cover it with manual steps described in this document.

We have planned schedules for weekdays only that will start VMs automatically at 6:00 AM and shutdown at 7:00 PM (Europe/Berlin time zone).

Deploy Start/Stop VMs v2

We followed mainly the official documentation for the start/stop VMs v2 function with great enthusiasm!

It is recommended to use separate resource group for deploying this application as it will create additional resources required for this function to work.

  1. Deploy function from the marketplace.

Azure Marketplace for Start / Stop Function

  1. Provide resource group, function, storage account and application insights names.

Configure Start/Stop Function

  1. After Deployment configure schedule for the sequenced stop.

Sequenced Schedule for Stop Function

  1. Configure schedule for the sequenced start.

Sequenced Schedule for Start Function

  1. Correct subscription information in the Logic app code view for the logic applications named ststv2_vms_Sequenced_stop and ststv2_vms_Sequenced_start

Update subscription information

  1. Enable Azure Function for the logic applications named ststv2_vms_Sequenced_stop and ststv2_vms_Sequenced_start

How to Configure VMs

Sequenced - Start and stop actions are based on a schedule targeting VMs with pre-defined sequencing tags. Only two named tags are supported - sequencestart and sequencestop. ststv2_vms_Sequenced_start and ststv2_vms_Sequenced_stop configure the sequenced start and stop.

The proper way to use the sequence functionality is to create a tag named sequencestart on each VM you wish to be started in a sequence. The tag value needs to be an integer ranging from 1 to N for each VM in the respective scope. The tag is optional and if not present, the VM simply won’t participate in the sequencing. The same criteria applies to stopping VMs with only the tag name being different and use sequencestop in this case. You have to configure both the tags in each VM to get start and stop action. If two or more VMs share the same tag value, those VMs would be started or stopped at the same time.

For example, the following table shows that both start and stop actions are processed in ascending order by the value of the tag.

VM Name Tags Action Order

VM 1

sequence start: 1 / sequence stop: 2

Start: VM1, VM2

VM 2

sequence start: 2 / sequence stop: 1

Stop: VM2, VM1

VM Tags

Tags must be set on the VMs to include or exclude specific VMs from start and stop actions. Add a tag named ssv2excludevm in the configuration for the VM. To exclude this VM from the start or stop action, set the value of this new tag to true. To include the VM in the action, set the value to false or don’t use any exclusion tag.

VMs sequence Order

VM Name Start Sequence Stop Sequence

RHIdM (Primary)

1

5

RHIdM (Replica)

NBDE (Primary)

NBDE (Replica)

RH Satellite

2

4

RH Keycloak

RH Bastion

3

3

AAP PGSQL

AAP Controller

4

2

AAP PAH

AAP EE

AAP HOP

AAP EE on DMZ

Capsule on DMZ

Workload VMs

5

1

Workload VMs on DMZ

RootCA

ssv2excludevm