How to create a simple Start/Stop schedule for Azure Virtual Machines

By Pete McLeavery, Senior Cloud Presales Engineer at Giacom

Hi! I’m Pete McLeavery, the Senior Cloud Presales Engineer at Giacom. In this blog, I’ll be covering one of the key benefits of using cloud: automatically turning your workloads on and off so you can save money.

I’ll be focussing on Virtual Machines (VM), and a simple but effective way to automate the Start/Stop schedule in scenarios where you don’t need that VM running 24/7.

You’d ideally keep some VMs switched on all the time, such as domain controllers and web servers. However, other environments such as remote desktops can be switched off outside of business working hours. Doing this will save on costs.

For example, running your workloads on pay-as-you-go for 220 hours per month will work out cheaper than having a VM always switched on with a reserved instance applied. With pay-as-you-go, you can easily turn the environments off when you don’t need them running.

Azure has a few different options for scheduling this Start/Stop feature, however I’ve I personally found the easiest method is using Logic App. Logic App is a resource in Azure that allows you to create and run automated workflows with little to no code. By using the visual designer feature, and selecting from prebuilt operations, you can quickly build a workflow that integrates and manages your apps, data, services, and systems.

So, in this example, we’re going to add a Logic App, and then schedule a simple Start/Stop which includes the specific times we want the VM to run.

Step 1: Creating a Logic App 💻

In the Azure portal, search for Logic Apps in the top search bar > select Logic Apps > Add.

You’ll then need to fill out the basic information related to this app.* Please see an example below. Then go to Review + Create > Create.

 

*Please note, in this example I’ve used the Consumption plan type which is perfect for workflows with a small amount of daily runs. For larger workflows, the Standard plan offers scaling and networking isolation.

Once created, select Logic App and go to Logic Apps Designer which is located on the left pane menu. Then go to Templates > Blank Logic App:

In the Connectors and Triggers search bar, search for Recurrence > Add. Then include the following options:

  • Set Interval: 1.
  • Set Frequency: Week.
  • Add New Parameter: Time zone. Then select your Time Zone.
  • Add New Parameter: Select ‘On these days’, then select the days you want this trigger to run. In this example, I’ve selected Monday – Friday. If you want a slightly different schedule, such as weekends, you can add a second Logic App for this.
  • Add New Parameter: Define the hours and minutes for the VM to run.
  • Then select the time you want this to start every morning.

After following these steps, you should see a window that looks like this:

Step 2: Adding actions to Virtual Machines ✍

The next step is to add some actions. Select ‘+ New Step’ > search for Start Virtual Machine.

Select Start Virtual Machine> Subscription > Resource Group > then select the Virtual Machine you want this action applied to.

Please note, if you want multiple Virtual Machines within the same recurrence, you can select the ‘+’ sign between recurrence and the ‘Start virtual machine’ box. Then select ‘Add a parallel branch’. You can then select the same ‘Start virtual machine’ action but select another VM to include.

Now that we’ve got a VM starting at 7am, the next step is to add a delay before we add another action, which will stop (deallocate) the Virtual Machine.

To do this, select + New step > Search and select Delay.

Then select the unit, and count for that unit. In this example, I want this to turn off at 7pm, so I’ll set the count to 12, and the units to hours.

Finally, we need to set a stop action for this Virtual Machine.

Select + New Item > Search for Deallocate Virtual Machine:

Then reselect the same VM you originally set to start. Once complete, click Save and you’re all set to go. You should now see something like this:

And it’s as easy as that. Once saved, you’ve got a Start/Stop schedule in place which will auto start and stop your Virtual Machines within your chosen timeframe.

I hope you’ve found this blog useful! If you have any questions or would like to discuss this further, please reach out to our team on 03304 333 888.