Skip to main content

Liferay Azure Automation With Runbooks

What is Azure Automation? Released to General Availability in October 2014. This feature allows you to automate many common aspects of using the Azure platform, integrating with other features such as web sites, cloud services and virtual machines.
Let's see how we can leverage Azure Automation to ensure usage costs are minimized, by only running Virtual Machines when they are going to be needed (Set to normal office hours 9 AM to 6 PM). This post shows how to schedule starting and stopping of virtual machines in Azure.
Step 1: Let's start off by accessing our Azure Automation section. Create an Automation account.





Step 2: Create Secure Assets for our new Automation Account.
What are Secure Assets? These include credentials, certificates, connections, and encrypted variables. These assets are encrypted and stored in the Azure Automation using a unique key that is generated for each automation account.
Let's firstly create credential named "MyAzureCredential", this helps us holding our Azure Credential and used as a dynamic variable utilized for our PowerShell Runbooks. See how it is used in Step 5.




Step 3: Create a variable named "SubscriptionName", this will helps us holding our Azure Subscription Name and used as a dynamic variable utilized for our PowerShell Runbooks. See how it is used in Step 5.




Step 4: Create our Runbook and provided the runbook name as "StartVM"



Step 5: Writing the Runbook PowerShell command. Select "Author" click on "Draft" input the PowerShell command.


Add the below PowerShell Script to the Draft section
workflow StartVM {
          #Input Parameters
          Param (
                   [parameter(Mandatory=$true)] [String] $VMName,  
                    [parameter(Mandatory=$true)] [String] $ServiceName
          )
          #Check for Weekend and exit the workflow in case of weekend
          $day = (Get-Date).DayOfWeek
          if ($day -eq 'Saturday' -or $day -eq 'Sunday'){ exit }
          #Fetch My Azure Credential stored in Assets of our Automation Account
          $credential = Get-AutomationPSCredential –Name "MyAzureCredential"
          #Add the Azure Account
          Add-AzureAccount -Credential $credential
          InlineScript {
                    #Fetch Subscription Name stored in Assets of our Automation Account
                    $subscriptionName = Get-AutomationVariable -Name "SubscriptionName"
                    #Select the Azure Subscription
                    Select-AzureSubscription -SubscriptionName $subscriptionName
          }
          #Start the Azure Machine
          Start-AzureVM -Name $VMName -ServiceName $ServiceName
}
Click on Test, this should the Strat Up the Virtual machine specified as the "VMName" & "ServiceName".
Once the PowerShell Script is working as expected, click on Publish.
Step 6: For the Runbook "StartVM" select "Schedule" Ć  "Link" Ć  "Link to a New Schedule".
We would set the Type (One Time / Hourly / Daily), & Start Time as required.




Now consider the time I specified is 9:00 AM, when the scheduled time arrives my specified Virtual Machine would Start Up.
For stopping the Virtual machine at a scheduled time of 6:00 PM, I would have to repeat the above procedure from Step 4 to Step 6.
The PowerShell Script would be modified as mentioned below:
workflow StopVM {
          #Input Parameters
          Param (
                    [parameter(Mandatory=$true)] [String] $VMName,  
                    [parameter(Mandatory=$true)] [String] $ServiceName
          )
          #Check for Weekend and exit the workflow in case of weekend
          $day = (Get-Date).DayOfWeek
          if ($day -eq 'Saturday' -or $day -eq 'Sunday'){ exit }
          #Fetch My Azure Credential stored in Assets of our Automation Account
          $credential = Get-AutomationPSCredential –Name "MyAzureCredential"
          #Add the Azure Account
          Add-AzureAccount -Credential $credential
          InlineScript {
                    #Fetch Subscription Name stored in Assets of our Automation Account
                    $subscriptionName = Get-AutomationVariable -Name "SubscriptionName"
                    #Select the Azure Subscription
                    Select-AzureSubscription -SubscriptionName $subscriptionName
          }
          #Stop the Azure Machine
          Stop-AzureVM -Name $VMName -ServiceName $ServiceName
}

Comments

Popular posts from this blog

Keyboard First Impressions: Kinesis Advantage Mechanical Ergonomic Keyboard

An ergonomic keyboard with mechanical switches that’s looking to attract users interesting in a high quality, highly ergonomic offering and don’t mind the rather steep learning curve or the price. The  TECK  isn’t the only such keyboard, of course, and I decided to see what other mechanical switch ergonomic keyboards I could get for comparison. Next up on the list is the granddaddy of high-end ergonomic keyboards, the  Kinesis Contour Advantage . I wanted to provide my first impressions of the Kinesis, along with some thoughts on the initial switch and the learning curve. This time, I also made the effort to put together a video of my first few minutes of typing. It actually wasn’t as bad as with the TECK, but that’s likely due to the fact that I already lost many of my typing conventions when I made that switch earlier this year. I’ll start with the video, where I take a typing test on four different keyboards and provide some thoughts on the experience, and then ...

Everything about Java 8

The following post is a comprehensive summary of the developer-facing changes coming in Java 8. This next iteration of the JDK is currently scheduled for general availability in  September 2013 . Read More

OnePlus 3T in 2017

Hi there, I just bought OnePlus 3T, why? Even when OnePlus 5 is out and OnePlus 5T looming around the corner. Top five reasons why the 3T might just be a very sound investment if you are in the market for a new phone. 3T is going for a relatively cheap price. Its wickedly fast. Its 1080p display. Its software. OnePlus 5 isnt a huge update. Key Specs Display - 5.50-inch Processor - 1.6GHz quad-core Front Camera - 16-megapixel Resolution - 1080x1920 pixels RAM - 6GB OS - Android 7.1.1 Storage - 64GB Rear Camera - 16-megapixel Battery Capacity - 3400mAh Overall Rating 9/10 - Design 9/10 - Display 9/10 - Software 9/10 - Performance 9/10 - Battery life 9/10 - Camera 9/10 - Value for money Important - No other phone with all round 9's. Good Solid system and app performance Very good battery life Competent set of cameras Amazing premium build quality Good value for money Bad Nothing as yet