Unable to connect to Azure VM Role for a long time after it is Deployed or Restarted

Saturday, January 22, 2011

I have been really frustrated in waiting for days to log in to my VM Role instance via RDP. I have encountered this issue multiple times. Once a VM Role is deployed or it is restarted, we can not login via RDP for a long period, and it takes a lot of time, sometimes 2-3 (random) days once it is back and allows us to connect via RDP.

Reason

This issue occurs due to a problem with the Azure Remote Forwarder Service, which runs in your VM Role instance. Due to this service sometimes RDP packets get distorted which cresults in connection timing out or closing it.

Solution

The solution I describe here is not really a solution, rather it is a workaround. The workaround is to set the Windows Azure Remote Forwarder Service from Automatic to Automatic – Delayed, by going to Service Management Console (Services.msc)






Startup Tasks in Azure Virtual Machine (VM ) Role

Friday, January 21, 2011

Since the release of Windows Azure SDK 1.3 we can now have startup tasks defined in the ServiceDefinition file for web/worker roles. However, this is not allowed for a Virtual Machine role. So what to do in case you need to have some tasks/scripts to be run on your VM Role’s startup? For example, your VM Role runs some software applications that require some configuration information that can be available only at run time.

So, how will you have startup tasks in a Virtual Machine Role? If you think that it’s just an easy task that involves adding you tasks in the Windows Startup folder (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup), then you are mistaken. This is not going to work as the tasks in the startup folders are executed only when a user logs in to the machine, but this is not what you want. Your tasks should run whenever your role is started.

The solution for this is to use VM Role Adapter. This basically involves creating a Windows Service that is configured to Start Automatically when windows start. This is really simple and involves following steps:

1. Create a WindowsService project in Visual Studio, let’s call it VMRoleStartup and write the operation you want to be executed at VM Role’s startup in the OnStart() method.


2. Add the installer class to the service by opening service’s class in designer mode and right-clicking. Select “Add Installer” from the menu as shown below. This class is used to install the service.

Add Project installer to Windows Service
Add Project installer to Windows Service

3. This will create a new class ProjectInstaller.cs with serviceInstaller and serviceProcessInstaller.

Project Installer Class
Project Installer Class


4. Go the properties of serviceProcessInstaller and select Account as LocalSystem. This is required so that the service will run as an administrator account.

Service Process Installer Properties
Service Process Installer Properties

5. Go to the properties of the serviceInstaller class and make following changes:

    • Make sure that the Service name is same as that of your Service name
    • Add Description and DisplayName as you want to be displayed in Services Management Console.
    • You can set DelayedAutoStart to True, to make sure that your VM role comes into a stable state before your tasks are started.
    • Set StartType to Automatic.

Service Installer Properties
Service Installer Properties


6. In the ProjectInstaller.cs class add the following code to start the service after it is installed.


Code to start windows service after installation
Code to start windows service after installation

Please note that MountXService here refers to your service class name.



7. Build the application under Any CPU or x64 platform (because VM Role runs under x64 platform).

8. Copy the .exe file (along with dlls if required) to VM Role and install it using installutil by running it from command prompt as an administrator user.
installutil” is available in “C:\Windows\Microsoft.Net\Framework64\v4.0.30319” path.


Install windows service using installutil
Install windows service using installutil

9. Upload your image to Azure and create a service model for VM Role to connect to this image.

This is it, now you are done and when your VM Role starts your windows service will be started and will execute the code you put up in it's OnStart method.

Azure VM Role CSUPLOAD Error 0x80070070 Cannot prepare VHD

Wednesday, January 5, 2011

Today I was trying to upload my base image to Azure via csupload so that i can attach this vhd to one of my virtual machine (VM) role. However, I got a strange error with no details. I kept on looking for the reason and finally I found the solution.

The error was as below:
Unexpected Error 0x80070070
Cannot prepare VHD C:\Users\user1\Desktop\baseimage.vhd

Reason:
The reason for this error as i discovered was that the disk from where it was uploaded was full. When you use csupload it uses temporary directory for preparing image and by default it uses the location from where you are uploading your base image. So if this disk is full you get this error.

Solution:
Delete some files from your drive to have more available space or use a location on another drive for temporary purpose using the switch TempLocation 

Followers

 

2009 ·Techy Freak by TNB