Technical Thursday – Scheduled VM start in Azure
In this week I would like to show you my latest automation solution for Azure. This is able to start a VM in Azure.
Everybody knows the automatic VM shutdown feature (Microsoft.DevTestLab/schedules) in Azure. It had been debutated in 2016. I love to use it for Azure developer servers because it can save cost and time for me. Nevertheless there is a small gap here. Why can’t start Azure my developer machine when I arrive to the office?
Now I make a ‘FIX” for this gap.
MyΒ Azure VM Manager solution helps you to start your VM in Azure at that time when you schedule. So when you arrive to your workplace your VM is up and running every time. π
Prerequisites
At the moment the v18.6.0 supports only Linux machines. Especially I have only tested on CentOS 7.
- Linux OS
- Azure-Cli 2.x
- Azure subscription
Step-by-step installation
- Pull the solution from my git
- Create a Service Principal for your account. More information is here
- Edit configuration file in config directory
{ "vmName": "<name of your vm>", "vmResourceGroup": "<vm resource group>", "azure": { "cloudName": "AzureCloud", "clientID": "<Service Principal ID>", "clientSecret": "<Service Principal Secret>", "tenant": "<Tenant ID>", "subscriptionID": "<Subscription ID>" } }
- Save configuration file
- Configure crontab according to your update requirement
# Edit crontab settings vim /etc/crontab ### Configure to start your vm at 9AM every weekdays 0 9 * * mon,tue,wed,thu,fri root cd /root/scripts/azvmmanager;bash azvmmanager.sh;
- Wait for the required time then check the logs according to execution in /var/log/azvmmanager directory
less /var/log/azvmmanager/azvmmanager20180614090001.log
part of log:
Thu Jun 14 09:00:29 CEST 2018 : # Login success Thu Jun 14 09:00:29 CEST 2018 : # Set default subscription Thu Jun 14 09:00:38 CEST 2018 : # Default subscription has been set Thu Jun 14 09:00:38 CEST 2018 : # Start VM: xxxxxxxxx
Let’s check your VM status in Azure. You can see it is up and running…
Please do not hesitate to contact me if you have any questions or feedback about this solution or Azure. π