-1

Is there a way to execute some script on Azure Web Role Instances ? I am kind off new to Azure and Azure Management APIs.

Basically what i want to achieve is, depending on the environment type, i would like to switch ON/OFF couple of services in all Azure Web Role Instances. So for e.g. if i have a single web role with 5 instances, then the script should execute in all the 5 instances.

  1. Determine the staging/production environment
  2. Get all the web roles for staging and production environment
  3. For each role get all the instances
  4. Run script in all instances (remotely)

Any help here would be much appreciated.

EDIT: I am able to fetch the staging/production environment details and the web role details for each environment as well. I am using the Service Management Rest APIs and the Get Cloud Service Properties method:

https://management.core.windows.net//services/hostedservices/?embed-detail=true

The above URL returns a list of role instance with their IP address.

But when i am trying to hit the Cloud Service (Web API) it is giving 404 error. Not sure if we can use the IP to hit a web api project hosted on IIS.

Thanks in advance, Jash

Jash
  • 942
  • 4
  • 17
  • 40
  • Using PowerShell, I believe the command you need is `Get-Deployment`, which will return a list of Input Endpoints for your instances. http://msdn.microsoft.com/en-us/library/azure/ee460804.aspx – Maria Ines Parnisari Jan 13 '15 at 01:24
  • @l19: GetDeployment is giving the Instance Endpoint details for each instance. The Input endpoint details are linked with VIP e.g. 3389 tcp Also when i am trying to use the Instance endpoint in the URL (ASP.NET WEB API), it is giving 504 error. – Jash Jan 14 '15 at 00:45
  • what kind of script you want to execute? you can connect over tcp endpoint to each of them, but you'll have to write code to handle the connection there... – d.popov Feb 14 '17 at 10:13

1 Answers1

0

Not exactly sure what you are trying to achieve. But if you have a Cloud Service with Web/Worker roles you cannot directly access each individual instance from the Internet. There is an Azure load balancer that sits in front of your deployment and routes Internet requests to instances. This would be useful for you to read.

What you can do, however, is to implement RoleEntryPoint class exactly like you would do for a Worker Role. Then you could check at regular intervals for a trigger - say a Blob in a container, a record in Table Storage, etc. When this happens - decide what to do: fetch special URL from Localhost, directly execute script with Process.Start(). Your choice, you have full control. All you have to do is to add a new class in your Web project that inherits from RoleEntryPoint.

You can refer to this resources for a bit more information on the use of RoleEntryPoint in WebRole projects:

astaykov
  • 30,768
  • 3
  • 70
  • 86
  • Thanks for the reply. Do you have any documentation on creating input endpoints for Web Role Instances. Also if we a web application, then can we access the web application with the input endpoint ? – Jash Jan 13 '15 at 23:49
  • okay i can see 2 input endpoints already declared in our csdef file. The name of the endpoints are HTTP and HTTPs on port 80 and 443 resp. Now with the help of GetDeployment() i am able to fetch the DIP (IP) for each instance. How should i now construct the URL to access the Instance ? – Jash Jan 13 '15 at 23:56
  • E.g. http://IP/xyz/.... where IP - IP address for the instance. Right now this is not working for me, and all the requests are giving 504 http error – Jash Jan 14 '15 at 00:17
  • As already stated in my answer - you **cannot** access individual role instances from the Internet. Read my answer once again to understand how to achieve your goal! – astaykov Jan 14 '15 at 07:25
  • Probably i read it wrong for the first time. Apologies. The problem with using RoleEntryPoint class is, we are not sure when we would require to run the script. During deployment we want to run this script on both production as well as staging boxes. – Jash Jan 14 '15 at 09:54
  • RoleEntryPoint defines a `while(true)` cycle in its `Run()` method. When combining with `Thread.Sleep(xxx)` you can perform action every `xx` seconds. And again, as stated in my answer - you can check a shared resource - a record in Azure Table or a blob in Azure Blob storage. And this will be checked by all your instances. – astaykov Jan 14 '15 at 10:23
  • sadly but this won't work for me. As you said if we can't access the role instances, then what is the purpose of input endpoints ? As is this documentation it is mentioned that input endpoints are for external communication - http://msdn.microsoft.com/en-us/library/azure/hh180158.aspx From Documentation: _Input endpoints are used to communicate with role instances from outside of Azure_ – Jash Jan 14 '15 at 11:30
  • sadly you really didn't read my blog post mentioned in the first paragraph of my answer. If you have done so, you would have understood why you cannot directly address an instance. – astaykov Jan 14 '15 at 12:03