Automated startup and shutdown of Azure VMs

This document describes in headlines how to setup automated start and shutdown of Azure VMs. To go through the steps, you are required to have access to the management portal at https://portal.azure.com and administration rights.

By shutting down the servers when not used there is a noticeable amount to be saved.

Prerequisites

Automation Account

To run the automation scripts, you need an Automation Account. Notice, that the account must be created under the same subscription as the servers that should be managed by the account.

The fastest way to locate the accounts is to search for the Automation Accounts service:

account1

To create a new account, click the Add button:

account2

Give the account a name, specify a resource group (or create a new) and a location:

account3

When created (it takes a moment), select the new account:

account4

Shut down servers

Runbooks

All activity is kept in runbooks. The account comes with 4 default runbooks which we for this scope leaves as is.

shutdown1

We are going to create our runbooks based on a template that gives us the functionality we need out of the box. To do this click Browse gallery:

shutdown2

The list of available templates is long. The first one we are going to use is the “Stop Azure V2 VMs”.

shutdown3

When we click on it we can see a graphical presentation of the flow. This is not relevant to go through in this document. Click the Import button to use the template:

shutdown4

Give the new runbook a name and a description:

shutdown5

After the runbook has been created, click Edit:

shutdown6

From here we can change the runbook including default values for the runbook. We can also test the runbook with different values.

In this case we are not going to change anything so we publish it right away by clicking the Publish button:

shutdown7

Scheduled runs

Next step is to schedule the runbook to run every afternoon. To do this click the Schedule button:

schedule1

To do this we need to things: A schedule and the parameters to run the runbook with. First the schedule:

schedule2

In this scenario we want the VMs to be stopped every day at 18:00:

schedule3

To run the runbook we need to specify the resource group name and the name of the VM.

schedule4

This information is found on the information page of the VM in the Azure portal.

Add it to the parameters:

schedule5

Now the scheduler will shut down the server matching the parameters every day at 18:00.

If you leave the VM name blank all servers in the resource group will be affected.

Starting VMs

To create a runbook to start the VMs go to the gallery and select the Start Azure v2 VMs template:

startup1

Give it a name and description:

startup2

Click edit to access the runbook just created:

startup3

Publish the runbook. Again we do not want to change anything:

startup4

Create a schedule to start the VM every working day at 7:00:00. In this case we don’t start them up in the weekends; but if somebody starts a VM it is automatically shut down by the previously created runbook.

startup5

You just saved a lot of money on the VM…

 

Create scheduled runs for every VM you can shut down at night.

 

Advertisements

Lifecycle Services and Azure Resource Manager – First bump on the road…

We have been using Lifecycle Services (LCS) for hosting environments for both AX 2012 and AX7 (sorry, New Dynamics AX) so it was somewhat a trivial task deploying new servers. Until we met Azure Resource Manager, that is. Adding servers to an old project ended up giving us this error message:

Lifecycle Services can’t connect to the Azure subscription using Azure Resource Manager. Click the Microsoft Azure Settings button and edit the selected Connector to provide the required permissions to ERP applications in your Azure subscription.

Error_message

The fix is fairly simple. Go to the Azure connector in your project. You’ll find it in the Project settings. Select it and click Edit. What you need to do is to flip this one to Yes:

Project_Flip_This

It will then lead you through a couple of steps regarding your management certificate and how you need to download it and upload it to the Azure Portal. No need to worry about that because you already did that when you created the connector so just click Next.

You could then end up with another obstacle in the form of missing rights on the Azure tier:

Project_Need_To_Add_Role

Go to Azure Portal and go to your subscription. Click this button to do add access:

Azure_Add_Access_Add

The following is pretty straight forward. Select a role and select the user:

Azure_Add_Access

Azure_Add_Access_Select_User

Azure_Add_Access_User_Done

Going back into LCS and click Next might present you with the same error like above with the Dynamics Deployment Service needs access but hang in there. It seems like there’s a bit of delay, so just give it another go after a minute or two.

As soon as your connector has been updated you’re good to go and can deploy the server.